2013年11月18日星期一

spring + active mq receive messages repeated problem

For example : the first send a message that reads "1" , the receiver will receive a message that reads "1 ." The second sends a message that reads "2" , the receiver will receive two messages , the content is " 1 ." What is this reason ? Looking for a long time did not find the cause of the problem . May be session problem?
<!-- 配置connectionFactory -->  
  <bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>tcp://192.168.61.125:61616</value>
</property>
</bean> 

<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="connectionFactory" />
</property>
        <property name="pubSubDomain" value="false" />  
        <property name="sessionAcknowledgeMode" value="2" /> 
</bean>
  <!-- 发送消息-->
    <bean id="destination" class="org.apache.activemq.command.ActiveMQTopic">  
        <constructor-arg index="0" value="com.topic" />  
    </bean>  
    
   <!-- 接收server消息 -->
   <bean id="webTopicDestination"
class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg index="0"
value="com.topic">
</constructor-arg>
</bean>

<!-- 接收消息监听的类 -->
<bean id="messageReceiver" class="com.mq.service.OnMessage">
    </bean>
    <!-- 消息监听     -->  
   <bean
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="concurrentConsumers" value="1" />
<property name="connectionFactory" ref="connectionFactory" />
<property name="destination" ref="webTopicDestination" />
<property name="messageListener" ref="messageReceiver" />
<property name="pubSubNoLocal" value="false"></property>
<property name="sessionTransacted" value="true" />
</bean> 

------ Solution ------------------------------------- -------
look at your code to the sender and the receiver of the code
------ Solution ------------------- -------------------------
disable the forwarding of relevant physical queue messages , try
<networkConnectors>
  <networkConnector uri="static://(tcp://localhost:61617)">
    <excludedDestinations>
  <queue physicalName="Consumer.*.VirtualTopic.>"/>
    </excludedDestinations>
  </networkConnector>
</networkConnectors>

------ Solution ------------------------------------- -------
will send you the information saved to the session, reception is taken from the session ?
------ For reference only -------------------------------------- -


momentary lack of attention , the test MQ when loaded in java code to send messages when the first load the configuration file template in access to send messages . At the receiving end listener to receive . Cause every time you send a message , we must re- load the configuration . Resulting in a duplication. Finally, the access application on a static variable to solve the duplication problem , in fact, is not sent repeatedly . Write code when there is no clear rationale led to drops, carefully read the code and found that the problem has now been solved. Thank you
------ For reference only ------------------------------------ ---

moment there is no note in the test MQ when loaded in java code to send messages when the first load the configuration file template in access to send messages . At the receiving end listener to receive . Cause every time you send a message , we must re- load the configuration . Resulting in a duplication. Finally, the access application on a static variable to solve the duplication problem , in fact, is not sent repeatedly . Write code when there is no clear rationale led to drops, carefully read the code and found that the problem has now been solved. Thank you
------ For reference only ------------------------------------ ---
moment there is no note in the test MQ when loaded in java code to send messages when the first load the configuration file template in access to send messages . At the receiving end listener to receive . Cause every time you send a message , we must re- load the configuration . Resulting in a duplication. Finally, the access application on a static variable to solve the duplication problem , in fact, is not sent repeatedly . Write code when there is no clear rationale led to drops, carefully read the code and found that the problem has now been solved. Thank you

没有评论:

发表评论