spring 整合 activemq
来源:互联网 发布:淘宝寄到日本 编辑:程序博客网 时间:2024/06/07 20:02
<!-- activeMq --> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-core</artifactId> <version>5.7.0</version> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> <version>5.13.0</version> </dependency><?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" 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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> <context:component-scan base-package="com.ita.activemq"></context:component-scan> <!-- ActiveMQ 连接工厂 --> <!-- 真正可以产生Connection的ConnectionFactory,由对应的 JMS服务厂商提供 --> <!-- 如果连接网络:tcp://ip:61616;未连接网络:tcp://localhost:61616 以及用户名,密码 --> <amq:connectionFactory id="amqConnectionFactory" brokerURL="tcp://10.222.29.155:61616" userName="admin" password="admin" /> <!-- Spring Caching连接工厂 --> <!-- Spring用于管理真正的ConnectionFactory的ConnectionFactory --> <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> <!-- 目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory --> <property name="targetConnectionFactory" ref="amqConnectionFactory"></property> <!-- 同上,同理 --> <!-- <constructor-arg ref="amqConnectionFactory" /> --> <!-- Session缓存数量 --> <property name="sessionCacheSize" value="100" /> </bean> <!-- A2M 队列1 --> <bean id="A2M" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg> <value>A2M</value> </constructor-arg> </bean> <!-- M2A 队列2 --> <bean id="M2A" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg> <value>M2A</value> </constructor-arg> </bean> <!-- 生产者 1 --> <!-- 定义JmsTemplate的Queue类型 --> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <!-- 这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象 --> <property name="connectionFactory" ref="connectionFactory" /> <property name="defaultDestination" ref="M2A" /> <property name="receiveTimeout" value="10000" /> <property name="pubSubDomain" value="false" /> </bean> <!-- 消息消费者监听器 配置对应的class --> <bean id="queueListener" class="com.ita.activemq.QueueMessageListener"></bean> <!-- 消费者1 监听器 --> <!-- --> <bean id="queueListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="connectionFactory" /> <property name="destination" ref="A2M" /> <property name="messageListener" ref="queueListener" /> </bean></beans> public class QueueMessageListener implements MessageListener { // 当收到消息后,自动调用该方法 @Override public void onMessage(Message message) { TextMessage tm = (TextMessage) message; try { System.out.println("QueueMessageListener监听到了文本消息:\t" + tm.getText()); // do something ... } catch (JMSException e) { e.printStackTrace(); } }}//@Repository(value = "sender")@Component(value = "sender")public class Sender { @Resource(name = "jmsTemplate") private JmsTemplate jmsTemplate; /** * 向指定队列发送消息 */ public void sendMessage(Destination destination, final String msg) { System.out.println("向队列" + destination.toString() + "发送了消息------------" + msg); jmsTemplate.send(destination, new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createTextMessage(msg); } }); } /** * 向默认队列发送消息 */ public void sendMessage(final String msg) { String destination = jmsTemplate.getDefaultDestination().toString(); System.out.println("向队列" + destination + "发送了消息------------" + msg); jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createTextMessage(msg); } }); }}
阅读全文
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整合
- 安装应用(APP) 不显示图标
- 常见的各种异常
- 对Dicom数据的一点理解
- 遗传算法深入学习上
- 500Keyboard Row
- spring 整合 activemq
- Servlet笔记——(2.4) ServletContext(重要)
- iOS开发 TableView的headerInSectionView 不悬浮
- 配置Tomcat使用https协议
- C#.NET MVC 导出WORD文档
- 导入图片的几种方式
- python学习第二天
- 微信小程序对接服装行业
- CUDA 9.0在Ubuntu上的安装