activeMQ发布订阅者模式使用
来源:互联网 发布:手机淘宝比价软件 编辑:程序博客网 时间:2024/06/05 22:49
发送方:
<!-- 配置 工厂 连接MQ -->
<bean id="activeMQConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://192.168.200.128:61616"/>
<property name="userName" value="admin"/>
<property name="password" value="admin"/>
</bean>
<!-- 连接池 -->
<bean id="pooledConnectionFactoryBean" class="org.apache.activemq.pool.PooledConnectionFactoryBean">
<property name="connectionFactory" ref="activeMQConnectionFactory"/>
</bean>
<!-- Spring -->
<bean id="singleConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory" ref="pooledConnectionFactoryBean"/>
</bean>
<!-- jmsTemplate -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="singleConnectionFactory"/>
<!-- 默认目标地名称 -->
<property name="defaultDestinationName" value="productId"/>
<!-- 发布者 publish
订阅者 Subject
模式 Domain
-->
<property name="pubSubDomain" value="true"/>
</bean>
接收方:
<!-- 配置 工厂 连接MQ -->
<bean id="activeMQConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://192.168.200.128:61616"/>
<property name="userName" value="admin"/>
<property name="password" value="admin"/>
</bean>
<!-- 连接池 -->
<bean id="pooledConnectionFactoryBean" class="org.apache.activemq.pool.PooledConnectionFactoryBean">
<property name="connectionFactory" ref="activeMQConnectionFactory"/>
</bean>
<!-- Spring -->
<bean id="singleConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory" ref="pooledConnectionFactoryBean"/>
</bean>
<!--自定义消息处理类 -->
<bean id="customMessageListener" class="com.core.service.message.CustomMessageListener"></bean>
<!-- 监听器 -->
<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="singleConnectionFactory"/>
<property name="destinationName" value="productId"/>
<property name="messageListener" ref="customMessageListener"/>
<!-- 发布者 publish
订阅者 Subject
模式 Domain
-->
<property name="pubSubDomain" value="true"/>
</bean>
自定义处理类
public class CustomMessageListener implements MessageListener{
@Autowired
private SearchService searchService;
@Override
public void onMessage(Message message) {
// TODO Auto-generated method stub
ActiveMQTextMessage atm = (ActiveMQTextMessage)message;
try {
String id = atm.getText();
System.out.println("Solr:" + id);
//保存商品信息到Solr服务器
searchService.insertProductToSolr(Long.parseLong(id));
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- activeMQ发布订阅者模式使用
- ActiveMQ发布订阅模式
- ActiveMQ发布订阅模式
- activemq 发布订阅模式
- ActiveMQ发布订阅模式
- ActiveMQ发布订阅模式
- activeMq的发布订阅模式
- ActiveMQ的发布订阅模式
- 使用Spring配置ActiveMQ的发布订阅模式
- 使用Spring配置ActiveMQ的发布订阅模式
- 3,ActiveMQ-Topic订阅发布模式
- ActiveMQ 发布订阅(Topic)
- ActiveMQ(4)-发布订阅
- ActiveMQ 快速入门教程系列 第二章 发布-订阅者模式实现
- activeMQ发布订阅模式中中常用工具类
- Spring整合activeMq(二):发布订阅模式
- activeMQ消息中间件之点对点与发布订阅模式实现
- Spring Redis与ActiveMQ发布订阅模式源码分析
- android 隐藏导航栏 状态栏 标题栏
- 【C语言】测试程序运行时间
- Course1_神经网络与深度学习_deeplearning.ai_andrew_ng
- 遗传算法之二进制编码
- 华为机试-字符串的分割
- activeMQ发布订阅者模式使用
- 传感器
- Spring Cloud开发注意事项
- 神经网络与深度学习(8)
- [NOIP2017模拟]构造
- 5. Longest Palindromic Substring(求最长回文子字符串)
- 封装Hibernate的Session操作和增删查改的工具类
- tomcat启动和停止时java.net.ConnectException:Connection refused:connect
- 如何在64位的Win10系统下安装.NET Framework 3.0