activeMQ
来源:互联网 发布:北京软件技术学院 编辑:程序博客网 时间:2024/06/06 02:44
activeMQ:消息中间件是在分布式系统中完成消息的发送和接受的基础软件
应用场景:
支付成功后由activeMQ进行后续的成本计算、商户计费、财务更新、风控归档等推送消息
有点对点模式和发布者订阅者模式(rabbitMQ)上架商品时项目中更改商品状态、发送消息到MQ中,商品信息保存到索引库,单品页静态化处理
点对点使用:
配置
发送方;
<!-- 配置 工厂 连接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"/>
</bean>
//发送消息 给MQ
jmsTemplate.send(new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
// TODO Auto-generated method stub
return session.createTextMessage(String.valueOf(id));
}
});
接收方:
<!-- 配置 工厂 连接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"/>
</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();
//保存商品信息到Solr服务器
searchService.insertProductToSolr(Long.parseLong(id));
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- ActiveMQ
- ACtiveMQ
- ACtiveMQ
- activeMQ
- ActiveMQ
- activeMQ
- activeMQ
- activemq
- ActiveMQ
- ActiveMQ
- ActiveMQ
- ActiveMQ
- activeMQ
- activemq
- ActiveMQ
- ActiveMQ
- ActiveMQ
- ActiveMQ
- 认识AngularJS
- PHP环境搭建之PHPstorm9+PHP5开发环境配置
- OracleASM参数介绍
- 三种方法的优先级
- poj2749 2-SAT
- activeMQ
- 通过射线检测 获取到某个点的颜色值
- 要写的博客
- Jquery中.attr()和.data()的区别
- 多线程编程(二)
- matlab路径(string)操作及基本data读取保存
- Caravan Robbers UVA
- 新手之路--spark
- matplotlib 时间轴绘图