Spring基于JMS实现远程访问
来源:互联网 发布:plc编程及应用第3版 编辑:程序博客网 时间:2024/09/21 08:58
使用JMS作为底层通信协议,spring提供了很好的支持。我们可以基于JMS将服务暴露给外部,这一切对于外部完全透明。这里我们基于开源消息中间件ActiveMQ作为中间代理,通过在服务端将服务以消息的形式发布到代理服务器上,然后客户端通过代理服务器实现对服务的远程调用。
ActiveMQ的BrokerService可以非常容易地实现服务端与客户端进行通信的中间代理,Spring配置broker.xml内容如下所示:
通过Spring的IOC容器来管理BrokerService。实现一个基于ActiveMQ的消息代理服务,如下所示:
启动后,代理监听61616,等待服务端发布服务,以及远程客户端调用服务。
看一下,服务端如何进行实现。
定义服务接口和服务实现。服务接口,代码如下所示:
实现上述接口,示例代码如下所示:
然后,服务端的配置server.xml,内容如下所示:
通过Spring的org.springframework.jms.listener.SimpleMessageListenerContainer实现服务的发布,可以配置的属性有:
connectionFactory 连接工厂
destination 消息目的地,基于ActiveMQ则是一个消息队列
concurrentConsumers 并发消息消费者数量
messageListener 消息监听器
taskExecutor 线程池
通过上面配置可以看到,连接工厂指定了代理监听服务的端口,我们通过服务端发布服务,作为消息生产者将服务以消息的形式发布,然后客户端作为服务的消费者,通过代理来实现对远程发布服务的调用。
服务端启动的实现,如下所示:
再看一下,客户端如何进行远程访问。
对应的客户端的配置client.xml,内容如下所示:
主要是基于Spring提供的org.springframework.jms.remoting.JmsInvokerProxyFactoryBean来实现,通过消息中间件代理,调用远程发布的服务。
需要注意的是,客户端是通过消息队列(org.apache.activemq.command.ActiveMQQueue)的名称(如上述为shirdrnQ)来获取消息(远程服务),如果无法识别消息队列是无法实现服务的远程访问的。
客户端实现远程访问,示例代码如下所示:
- Spring基于JMS实现远程访问
- Spring基于JMS实现远程访问
- Spring基于JMS实现远程访问
- Spring 实现远程访问详解——jms和activemq
- JMS--Spring整合JMS(一)——基于ActiveMQ实现
- spring整合JMS - 基于ActiveMQ实现
- spring整合JMS - 基于ActiveMQ实现
- spring整合JMS - 基于ActiveMQ实现
- spring integration JMS-基于ActiveMQ实现
- Spring整合JMS(一)-基于ActiveMQ实现
- Spring整合JMS基于ActiveMQ实现
- Spring整合JMS——基于ActiveMQ实现
- Spring整合JMS——基于ActiveMQ实现
- Spring整合JMS(一)——基于ActiveMQ实现
- Spring整合JMS(一)——基于ActiveMQ实现
- Spring整合Jms学习(一)_基于ActiveMQ实现
- Spring整合JMS(一)——基于ActiveMQ实现
- Spring整合JMS(一)---基于activeMQ的实现
- 蓝瘦,香菇,我为什么还没有用上WPG闪电充
- 82. Remove Duplicates from Sorted List II
- 软件工程 - 个人博客系统 - 概要设计与详细设计文档
- 盘点3款原型工具的部件样式
- Java多线程学习
- Spring基于JMS实现远程访问
- DWR的工作原理和优缺点
- oracle导入导出dmp文件
- Android菜鸟练习第一课 调用系统裁剪功能裁剪图片上传服务器
- (二十一)内存溢出解决方法---学习笔记
- iOS 画虚线方法总结
- 一个合格的程序员应该读过哪些书
- java面试题
- Linux usb wifi驱动分析(一)