activemq发送topic消息,接收了两次
< 返回列表时间: 2016-01-04来源:开源中国
HDC调试需求开发(15万预算),能者速来!>>>
使用spring + activemq 框架,发送topic消息,在接收端接收了两次消息,但使用queue却不会出现这种情况。
xml配置如下
<!-- 配置connectionFactory --> <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop"> <property name="connectionFactory"> <bean class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL"> <value>tcp://127.0.0.1:61616</value> </property> </bean> </property> <property name="maxConnections" value="100"></property> </bean> <!-- 发送消息的目的地(一个队列) --> <bean id="destQueue" class="org.apache.activemq.command.ActiveMQQueue"> <!-- 设置消息队列的名字 --> <constructor-arg index="0" value="queue" /> </bean> <bean id="messageConverter" class="com.andeveloper.springdemo.mq.ActiveMQMessageConverter" /> <!-- Spring JMS Template --> <bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory"> <ref local="jmsFactory" /> </property> <property name="defaultDestination" ref="destQueue" /> <!-- 区别它采用的模式为false是p2p为true是订阅 --> <property name="pubSubDomain" value="false" /> <property name="messageConverter" ref="messageConverter"></property> </bean> <!-- 发送消息的目的地(一个主题) --> <bean id="destTopic" class="org.apache.activemq.command.ActiveMQTopic"> <!-- 设置消息队列的名字 --> <constructor-arg index="0" value="topic" /> </bean> <!-- Spring JMS Template --> <bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory"> <ref local="jmsFactory" /> </property> <property name="defaultDestination" ref="destTopic" /> <!-- 区别它采用的模式为false是p2p为true是订阅 --> <property name="pubSubDomain" value="true" /> <property name="messageConverter" ref="messageConverter"></property> </bean> <bean id="messageQueueListener" class="com.andeveloper.springdemo.mq.ActiveMQMessageQueueListener" /> <bean id="messageQueueContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="jmsFactory"></property> <property name="destination" ref="destQueue"></property> <property name="messageListener" ref="messageQueueListener"></property> </bean> <bean id="messageTopicListener1" class="com.andeveloper.springdemo.mq.ActiveMQMessageTopicListener1" /> <bean id="messageTopicContainer1" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="jmsFactory"></property> <property name="destination" ref="destTopic"></property> <property name="messageListener" ref="messageTopicListener1"></property> </bean>
热门排行