我创建了一个rebbitmq fanout Exchange示例集成spring,但只有一个订阅可以接收消息,为什么?我的配置如下: 发布配置
<rabbit:connection-factory id="connectionFactory" username="dev" password="dev" host="localhost" />
<rabbit:template id="template" connection-factory="connectionFactory" reply-timeout="2000" exchange="2remoting.exchange" />
<rabbit:admin connection-factory="connectionFactory" />
<rabbit:queue name="remoting.queue1" />
<rabbit:fanout-exchange name="2remoting.exchange" >
<rabbit:bindings>
<rabbit:binding queue="remoting.queue1"/>
</rabbit:bindings>
</rabbit:fanout-exchange>
订阅配置
<bean id="service" class="com.hzins.bsp.dev.TestServiceImpl" />
<rabbit:connection-factory id="connectionFactory" username="dev" password="dev" host="localhost" />
<rabbit:template id="template" connection-factory="connectionFactory" />
<rabbit:queue name="remoting.queue1" />
<rabbit:listener-container connection-factory="connectionFactory">
<rabbit:listener ref="listener" queue-names="remoting.queue1" />
<rabbit:listener ref="listener" queue-names="remoting.queue1" />
</rabbit:listener-container>
最佳答案
不,您误解了扇出交换
的定义。它将消息放入所有绑定(bind)队列,但不订阅这些队列。
同一个队列有多少订阅者(监听器)没有值(value)。他们只是并发消费者,只有其中一个会从队列中接收消息。
请阅读更多 RabbitMQ 文档。
关于java - 为什么rabbitmq fanout Exchange只能收到一个订阅消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28792778/