spring 整合 ActiveMQ
来源:互联网 发布:c语言中match函数 编辑:程序博客网 时间:2024/06/16 12:10
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.1.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.12.1.xsd"><!-- 自动扫描包路径下名字--><context:component-scan base-package="sa.Stu"/><mvc:annotation-driven/><!-- 配置mq的连接--><amq:connectionFactory id="amqConnectionFactory"brokerURL="tcp://localhost:61616"userName="admin"password="admin"/><!-- 配置JMS连接工厂--><bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"><constructor-arg ref="amqConnectionFactory"/><property name="sessionCacheSize" value="100"/></bean><!-- 定义消息队列(Queue),默认的 目标地址 --> <bean id="demoQueueDestination" class="org.apache.activemq.command.ActiveMQQueue"> <!-- 设置消息队列的名字 --> <constructor-arg> <value>Jaycekon</value> </constructor-arg> </bean> <!-- 配置JMS模板(Queue),Spring提供的JMS工具类,它发送、接收消息。 --> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="connectionFactory" /> <property name="defaultDestination" ref="demoQueueDestination" /> <property name="receiveTimeout" value="10000" /> <!-- true是topic,false是queue,默认是false,此处显示写出false --> <property name="pubSubDomain" value="false" /> </bean> <!--配置消息队列监听者 ,自己定义的一个监听器类--><bean id="queueMessageListener" class="sa.Stu.Filter.QueueMessageListener"></bean><!-- 显示注入消息监听容器(Queue),配置连接工厂,监听的目标是demoQueueDestination,监听器是上面定义的监听器 --> <bean id="queueListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="connectionFactory" /> <property name="destination" ref="demoQueueDestination" /> <property name="messageListener" ref="queueMessageListener" /> </bean> </beans>网上的例子。
利用了 spring提供的spring-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="jmsTargetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"><property name="brokerURL"><value>tcp://localhost:61616</value></property><property name="userName"><value>admin</value></property><property name="password"><value>admin</value></property></bean><!-- 建立连接池,activemq提供的 --><bean id="jmsPooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"><property name="connectionFactory" ref="jmsTargetConnectionFactory" /><property name="maxConnections" value="5" /></bean><!-- 这是spring 内在集成的的连接,可以实现对事物的管理,这样MQ的事物交给 spring来进行管理,CachingConnectionFactory
和SingleConnectionFactory 两种方式
有两种这里是融合spring与activeMQ的关键-->
<bean id="jmsConnectionFactory"class="org.springframework.jms.connection.SingleConnectionFactory"><property name="targetConnectionFactory" ref="jmsPooledConnectionFactory" /></bean><!--利用spring 的 jmsTemplate 的模版实现 --><bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"><property name="connectionFactory" ref="jmsConnectionFactory" /></bean><!--自定义一个 监听器 --> <bean id="messageReceiver" class="com.hkrt.app.offlinepos.listener.MercQuickApplyListener"> <property name="testService" ref="testService" />/> </bean> <!--建立一个默认的 destination 地址 --><bean id="syncRechargeDestination" class="org.apache.activemq.command.ActiveMQQueue"><constructor-arg><value>mercapply-queue</value></constructor-arg><!-- 消息监听容器 ,DefaultMessageListenerContainer 默认的spring容器监听器 --> <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="jmsPooledConnectionFactory" /> <property name="destination" ref="syncRechargeDestination" /> <property name="messageListener" ref="messageReceiver" /> </bean>
<bean/>
阅读全文
0 0
- ActiveMQ(四):Spring ActiveMQ 整合
- ActiveMQ和spring整合
- Spring整合ActiveMQ
- SPRING+ACTIVEMQ+TOMCAT整合
- Spring整合activeMQ
- ActiveMQ、Spring整合学习
- activeMq整合spring
- ActiveMQ、Spring整合学习
- spring activemq quartz 整合
- SPRING JMS 整合ACTIVEMQ
- ActiveMQ整合Spring
- 【参考】spring整合activemq
- Spring整合ActiveMQ
- spring+activemq整合学习
- spring 整合 activemq 配置文件
- Spring整合ActiveMQ
- Spring与ActiveMQ整合
- ActiveMQ和spring整合
- 93. Restore IP Addresses(unsolved)
- 基于深度学习的服装图像分类与检索
- Spring如何配置bean属性
- Material Design设计(Android5.0新特性)
- 按下Backspace键,就会跳转到上一个页面。JavaScript屏蔽Backspace键处理,禁用Backspace键。
- spring 整合 ActiveMQ
- 反射机制
- 实现MERGE操中获取UPDATE行数和INSERT行数
- 伴随Tomcat启动的线程无法启动 Unsopported major.minor version 52.0
- gethostbyname()使用
- springboot 入门
- C语言中,打印数据类型的取值范围l的两种方法
- HttpURLConnection无法打开含有中文的链接
- JAVA8 十大新特性详解