Spring整合activityMq
来源:互联网 发布:尚学堂大数据 编辑:程序博客网 时间:2024/06/03 18:57
1. spring.xml 配置文件
ActiveMQ 连接工厂
真正可以产生Connection的ConnectionFactory,由对应的 JMS服务厂商提供
如果连接网络:tcp://ip:61616;未连接网络:tcp://localhost:61616 以及用户名,密码
<amq:connectionFactory id="amqConnectionFactory"
brokerURL="tcp://localhost: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>
Spring JmsTemplate 的消息生产者 start
定义JmsTemplate的Queue类型
<bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate">
这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象
<constructor-arg ref="connectionFactory" />
非pub/sub模型(发布/订阅),即队列模式
<property name="pubSubDomain" value="false" />
<property name="defaultDestinationName" value="test.queue" />
</bean>
Spring JmsTemplate 的消息生产者 end
消息消费者 start
定义Queue监听器
<jms:listener-container destination-type="queue" container-type="default" connection-factory="connectionFactory" acknowledge="auto">
<jms:listener destination="test.queue" ref="messageReceiver"/>
</jms:listener-container>
2. 创建 MessageReceiver 实现 MessageListener 重写 onMessage 方法,处理消息 (监听到消息到了,然后进行处理消息)
3.发送消息
@Autowired
private JmsTemplate jmsTemplate;
jmsTemplate.send(new MessageCreator(){
public Message createMessage(Session session)
throws JMSException {
TextMessage message = session.createTextMessage();
message.setText("TopicPublisherService 发送消息" + new Date());
message.setJMSReplyTo(destination);//反馈信息
return message;
}
})
4.接收消息
public void onMessage (Message message){
if(msg instanceof TextMessage){
TextMessage textMessage = (TextMessage) msg;
try {
System.out.println("--订阅者 MessageListener收到信adfadfafasdfasd:"+textMessage.getText());
} catch (JMSException e) {
e.printStackTrace();
}
}
}
- Spring整合activityMq
- maven+spring整合activitymq-all启动报错
- activityMQ
- spring boot Activitymq topic与 queue 并存实现方案
- ActivityMQ 事务
- ActivityMQ 事务
- SpringMVC-整合Spring整合
- spring整合
- Spring整合
- ActivityMQ (1) 简介
- ActivityMQ android开发
- JSM之ActivityMQ
- ActivityMQ中的使用详解
- ActivityMQ的实现原理
- ActivityMQ入门案例
- ActivityMQ应用详解
- Spring -- spring整合struts2
- Spring、整合Spring+JDBC
- [FAQ17627]电信自注册基础知识
- Unity3d学习笔记(3)--牧师与魔鬼游戏
- Genymotion ERR_NAME_NOT_RESOLVED
- React之ref详细用法
- Swift 协议关系图
- Spring整合activityMq
- 全面了解 Nginx 主要应用场景
- 考研复试系列——第十二节 后缀表达式&约瑟夫环
- jQuery性能优化与技巧
- 安卓旧项目使用Small框架插件化改造踩坑记
- zookeeper学习系列:三、利用zookeeper做选举和锁
- nodejs模块的引入简易demo
- datetimebox输入开始结束日期,JS中自动计算天数并赋给input框
- 107. Binary Tree Level Order Traversal II