[英]Consume DirectExchange messages using routing key and exchange in spring boot
Am trying to consume the message from exiting queue which is of type Direct Exchange (created with the help of exchange and routing key). 我正在尝试从直接交换类型(借助交换和路由密钥创建)的退出队列中使用消息。 I have only the exchange name and routing key and not the queue name .
我只有交换名称和路由密钥,而没有队列名称 。 There were support for plain Java, but there was no place where I can find it for Spring boot.
有对纯Java的支持,但是没有地方可以在Spring引导中找到它。
@RabbitListener
@RabbitHandler
public void consumeMessage(Object message) {
LOGGER.debug("Message Consumed.... : {}", message.toString());
}
How can I consume messages with routing key and exchange name not the queue name as @RabbitListener
asks for queue
. 我如何使用带有路由键和交换名而不是队列名的消息来使用消息,而不是
@RabbitListener
要求queue
。
Consumers consume from queues not exchanges. 消费者从队列而不是交换中消费。 You must bind a queue to the exchange with the routing key.
您必须使用路由密钥将队列绑定到交换机。
EDIT 编辑
There are several ways to automatically declare a queue on the broker. 有几种方法可以在代理上自动声明队列。
@RabbitListener(bindings =
@QueueBinding(exchange = @Exchange("myExchange"),
key = "myRk", value = @Queue("")))
public void listen(String in) {
System.out.println(in);
}
This will bind an anonymous queue (auto-delete) which will be deleted when the application is stopped. 这将绑定一个匿名队列(自动删除),该匿名队列在应用程序停止时将被删除。
@RabbitListener(bindings =
@QueueBinding(exchange = @Exchange("myExchange"),
key = "myRk", value = @Queue("foo")))
public void listen(String in) {
System.out.println(in);
}
Will bind a permanent queue foo
to the exchange with the routing key. 将使用路由键将永久队列
foo
绑定到交换。
You can also simply declare #Bean
s for the queue, exchange and binding. 您也可以简单地声明
#Bean
来进行队列,交换和绑定。
See Configuring the broker . 请参阅配置代理 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.