Adding multiple listeners which will listen to different RabbitMQ queue not working

我的未来我决定 提交于 2019-12-06 07:23:59

问题


I hava following spring xml configuration

<bean id="connectionFactory"
          class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
 <constructor-arg value="xxxxxxxx"/>
        <property name="username" value="xxxxx"/>
        <property name="password" value="xxxxx"/>
        <property name="channelCacheSize" value="25"/>
        <property name="virtualHost" value="/"/>
        <property name="port" value="3453"/>
 </bean>

 <rabbit:template id="tutorialTemplate" connection-factory="connectionFactory"/>
 <!-- 1st queue -->             
 <rabbit:queue id="veliteQueue" name="ES_queue" durable="true" auto-delete="false" exclusive="false"/>

 <rabbit:direct-exchange id="myExchange" durable="true" name="ES_exchange">
     <rabbit:bindings>
        <rabbit:binding queue="veliteQueue" key="logstash"></rabbit:binding>
     </rabbit:bindings>
 </rabbit:direct-exchange>

  <!-- 2nd Queue -->
 <rabbit:queue id="veliteQueue1" name="ES_queue_Temp" durable="true" auto-delete="false" exclusive="false"/> 

  <rabbit:direct-exchange id="myExchange1" durable="true" name="ES_exchange_temp">
    <rabbit:bindings>
        <rabbit:binding queue="ES_queue_Temp" key="logstash_temp"></rabbit:binding>
    </rabbit:bindings>
   </rabbit:direct-exchange> 
   <!-- 2 Listeners for 2 queue's mentioned above --> 
   <bean id="aListener" class="com.vzw.es.cosumer.SpringMessageListener" autowire="byName"/>
<bean id="aListener1" class="com.vzw.es.cosumer.SpringMessageListener1" autowire="byName"/>

<rabbit:listener-container id="myListenerContainer" connection-factory="connectionFactory" acknowledge="auto" prefetch="750" concurrency="1">
    <rabbit:listener ref="aListener" queues="veliteQueue"/>
    <rabbit:listener ref="aListener1" queues="veliteQueue1"/>
</rabbit:listener-container>

Now in my Java code I have 2 Listener classes com.vzw.es.cosumer.SpringMessageListener and com.vzw.es.cosumer.SpringMessageListener1. Now When I am running my main class only 1 listener's onMessage method is getting invoked i.e. SpringMessageListener1, I did check from RabbitMQ prespective and bothe queues have enough messages to consume. Spring / Rabbitmq master can you please help me solving this problem. Also when I comment out the 2nd queue and its listener from xml SpringMessageListener works perfectly.


回答1:


It's a bug in the container parser, each listener gets its own container (the namespace is just a convenient way to specify common attributes). If you remove the id="myListenerContainer", it will work - because each container gets a (different) generated name. With the id specified, both beans get the same name, and the last definition replaces the first.

Alternatively, declare two separate container elements, with different IDs, and each having just one listener.

Thanks for finding this.

Please open a JIRA issue

EDIT: This issue was resolved in version 1.2.1.



来源:https://stackoverflow.com/questions/18726421/adding-multiple-listeners-which-will-listen-to-different-rabbitmq-queue-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!