active mq 消费
2015-11-23 14:39
197 查看
首先配置MQ connection
配置队列
配置listener
监听类 实现messageListener
消费容器可以使用
<bean id="amqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="failover://@{amq.address}?randomize=false&jms.useAsyncSend=true&jms.prefetchPolicy.queuePrefetch=1" /> </bean> <bean id="pollConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" > <property name="connectionFactory" ref="amqConnectionFactory" /> <property name="maxConnections" value="@{maxConnections}"/> </bean>
配置队列
<bean id="priceInfoQueue" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg index="0" value="@{price.amq.queue.name}" /> </bean>
配置listener
<bean id="priceListener" class="com.mq.listener.ProductPriceListener" /> <bean id="priceConsume" class="com.mq.consume.PriceMQConsume"> <property name="connectionFactory" ref="amqConnectionFactory" /> <property name="destination" ref="priceInfoQueue" /> <property name="messageListener" ref="priceListener" /> <property name="receiveTimeout" value="10000" /> <property name="sessionTransacted" value="true" /> <property name="sessionAcknowledgeMode" value="0" /> </bean>
监听类 实现messageListener
public class ProductPriceListenerimplements MessageListener { private static final Logger logger = LoggerFactory.getLogger(
ProductPriceListener.class); @Override public void onMessage(Message message) { if (!(message instanceof TextMessage)) { logger.warn("Only TextMessage will be processed."); return; } try {//消费代码 } catch (Exception e){ //异常 } }}
消费容器可以使用
org.springframework.jms.listener.DefaultMessageListenerContainer
public class PriceMQConsume extends DefaultMessageListenerContainer { }
相关文章推荐
- 在 Perl 中使用 Getopt::Long 模块
- weblogic.descriptor.DescriptorException: VALIDATION PROBLEMS WERE FOUND
- MPN旗下Poker Heaven宣布关闭
- Codeforces Round332 部分题解
- python 的expect,paramiko ssh交互使用
- Android关于Theme.AppCompat相关问题的深入分析
- 053-9 To view the results of a manual SQL Tuning Advisor task, which steps should the DBA take?
- 乐观锁与悲观锁
- 为什么要跟新数据库(SQList)
- 最佳线程数总结
- jquery的submit函数提交顺序
- 自动跳转页面
- 老鸟需要知道的一些php系统类函数
- POJ-1080- Human Gene Functions-DP-LCS变形
- eclipse ---修改新建jsp模板
- 禁止ViewPager预加载的问题
- MySQL字符串中数字排序的问题
- mysql存在更新,不存在增加
- AsyncTask异步机制
- 数据结构(Java)——二叉树的应用