Spring之JMS
来源:互联网 发布:淘宝宝贝排名下降了 编辑:程序博客网 时间:2024/04/27 23:16
使用JMS作为底层通信协议也能暴露service。Spring框架的JMS远程支持是非常简单的。在同一线程和同一非事物会话上发送和接受,并且吞吐量也将是非常依赖于实现的。注意这些单线程和非事物约束仅应用于Spring的jms远程支持。
下面的接口用于服务器端和客户端。
package com.foo;public interface CheckingAccountService { public void cancelAccount(Long accountId);}
下面是上述接口的简单实现用于服务器端:
package com.foo;public class SimpleCheckingAccountService implements CheckingAccountService { public void cancelAccount(Long accountId) { System.out.println("Cancelling account [" + accountId + "]"); }}
这个配置文件包含了JMS使用的beans,用于客户端和服务器端。
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://ep-t43:61616"/> </bean> <bean id="queue" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="mmm"/> </bean></beans>
21.6.1 服务器端配置
在服务器端,你仅需要使用JmsInvokerServiceExporter暴露你的业务对象。
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="checkingAccountService" class="org.springframework.jms.remoting.JmsInvokerServiceExporter"> <property name="serviceInterface" value="com.foo.CheckingAccountService"/> <property name="service"> <bean class="com.foo.SimpleCheckingAccountService"/> </property> </bean> <bean class="org.springframework.jms.listener.SimpleMessageListenerContainer"> <property name="connectionFactory" ref="connectionFactory"/> <property name="destination" ref="queue"/> <property name="concurrentConsumers" value="3"/> <property name="messageListener" ref="checkingAccountService"/> </bean></beans>
package com.foo;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Server { public static void main(String[] args) throws Exception { new ClassPathXmlApplicationContext(new String[]{"com/foo/server.xml", "com/foo/jms.xml"}); }}
21.6.2 客户端配置
客户端仅需要创建一个客户端的代理,将实现通过协议的上述接口(CheckingAccountService)。由下面bean定义创建的结果对象可以注入到另一个客户端对象,并且代理将通过JMS保持对服务器端对象的调用。
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="checkingAccountService" class="org.springframework.jms.remoting.JmsInvokerProxyFactoryBean"> <property name="serviceInterface" value="com.foo.CheckingAccountService"/> <property name="connectionFactory" ref="connectionFactory"/> <property name="queue" ref="queue"/> </bean></beans>
package com.foo;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Client { public static void main(String[] args) throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] {"com/foo/client.xml", "com/foo/jms.xml"}); CheckingAccountService service = (CheckingAccountService) ctx.getBean("checkingAccountService"); service.cancelAccount(new Long(10)); }}
0 0
- Spring之JMS
- Spring消息(1)之 JMS
- Spring之JMS之消息监听容器
- Spring之JMS之发送消息
- Spring之JMS之接受消息
- Spring之JMS之接受消息
- Spring之JMS之发送消息
- Spring之JMS之接受消息
- JMS之Spring +activeMQ实现消息队列
- spring---消息订阅发布之JMS
- spring -jms
- Spring JMS
- Spring JMS
- spring jms
- spring+jms
- spring + jms
- jms spring
- spring jms
- Mysql中插入字段同时等于主键ID
- JDK 各版本下载地址
- mysql相关语句
- 解压缩命令tar 学习
- 触发隐藏按钮的onclick事件 注意事项
- Spring之JMS
- CreateFileMapping用法
- 对jQuery的事件绑定的一些思考
- 帮助妈妈做些有意义的事情能帮助亲人之余也可以学到知识
- 【Unity Shaders】初探Surface Shader背后的机制
- js对象Object
- IP地址在数据库中的存储方式
- 第二章一些概念1
- C/C++值传递和引用传递