我有以下spring xml配置
<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>
现在在我的 Java 代码中,我有 2 个侦听器类:com.vzw.es.cosumer.SpringMessageListener 和 com.vzw.es.cosumer.SpringMessageListener1。现在,当我运行我的主类时,只有 1 个侦听器的 onMessage 方法被调用,即 SpringMessageListener1,我确实从 RabbitMQ 进行了检查,并且两个队列都有足够的消息来消费。
此外,当我从 xml SpringMessageListener 注释掉第二个队列及其侦听器时,它的效果也很好。