我一整天都碰到了这个问题,非常讨厌,但我现在把这个问题提交给社区,希望有人可以帮助我
这是我的配置:
<rabbit:connection-factory id="connectionFactory"
virtual-host="****" username="****" password="****" />
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" />
<rabbit:admin connection-factory="connectionFactory" />
<rabbit:queue name="a" durable="true" />
<rabbit:queue name="b" durable="true" />
<rabbit:listener-container prefetch="10"
task-executor="taskExecutor" acknowledge="auto"
transaction-size="10" connection-factory="connectionFactory"
concurrency="10" channel-transacted="false"
message-converter="jsonMessageConverter" requeue-rejected="false">
<rabbit:listener id="a-listener" ref="Abean"
method="listen" queue-names="a" />
<rabbit:listener id="b-listener" ref="Bbean"
method="listen" queue-names="b" />
</rabbit:listener-container>
<bean id="Abean"
class="****" />
<bean id="Bbean"
class="****" />
<rabbit:direct-exchange name="****"
durable="true">
<rabbit:bindings>
<rabbit:binding queue="a" key="a" />
<rabbit:binding queue="b"
key="b" />
</rabbit:bindings>
</rabbit:direct-exchange>
启动上下文后,没有错误,看来只有配置的第一个监听器(a-listener)才会让消费者连接到它感兴趣的队列(a)。但是,另一个监听器,没有什么,没有消费者连接到队列(b)。
此配置有什么问题?
我正在使用最新的spring-amqp(1.5.4.Release)
答案 0 :(得分:2)
我刚刚复制了你的配置并运行了这个测试...
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class Foo {
@Autowired
private RabbitTemplate template;
@Autowired
private FooListener Abean;
@Autowired
private FooListener Bbean;
@Test
public void test() throws Exception {
template.convertAndSend("sotest", "a", "foo");
template.convertAndSend("sotest", "b", "bar");
assertTrue(Abean.latch.await(10, TimeUnit.SECONDS));
assertTrue(Bbean.latch.await(10, TimeUnit.SECONDS));
}
public static class FooListener {
private final CountDownLatch latch = new CountDownLatch(1);
public void listen(byte[] foo) {
System.out.println("received:" + foo);
latch.countDown();
}
}
}
......它运作良好。
你不能展示你的taskExcecutor
豆;也许你的任务执行者只有一个线程?