简体   繁体   English

仅从 Spring 云 stream 和 RabbitMQ 中的特定路由键消费

[英]Consume only from a specific routing key in Spring cloud stream with RabbitMQ

In Cloud Stream for RabbitMQ I want to set a consumer that will consume from a Queue only the messages that have been forwarded with a specific routing key.在 Cloud Stream for RabbitMQ 中,我想设置一个消费者,该消费者将从队列中仅消费已使用特定路由键转发的消息。 Is this possible?这可能吗?

Here are my application.properties.这是我的 application.properties。

Producer :生产商

spring.cloud.stream.rabbit.bindings..consumer.bindQueue=false
spring.cloud.stream.rabbit.bindings..consumer.declareExchange=false
spring.cloud.stream.bindings.producer1-out-0.destination=exchange1
spring.cloud.stream.rabbit.bindings.producer1-out-0.producer.routingKeyExpression='routing.key.1'

Consumer :消费者

spring.cloud.stream.rabbit.bindings..consumer.bindQueue=false
spring.cloud.stream.rabbit.bindings..consumer.declareExchange=false
spring.cloud.stream.bindings.consumer1-in-0.destination=exchange1
spring.cloud.stream.bindings.consumer1-in-0.group=reports
spring.cloud.stream.rabbit.bindings.consumer1-in-0.consumer.queueNameGroupOnly=false
spring.cloud.stream.rabbit.bindings.consumer1-in-0.consumer.bindingRoutingKeyDelimiter=,
spring.cloud.stream.rabbit.bindings.consumer1-in-0.consumer.bindingRoutingKey='routing.key.1'

Exchanges and bindings are defined directly in RabbitMQ.交换和绑定直接在 RabbitMQ 中定义。

My expectation was if I change spring.cloud.stream.rabbit.bindings.consumer1-in-0.consumer.bindingRoutingKey to something else the consumer will stop consuming but it's not the case.我的期望是,如果我将spring.cloud.stream.rabbit.bindings.consumer1-in-0.consumer.bindingRoutingKey更改为消费者将停止消费的其他内容,但事实并非如此。

No;不; unlike JMS, RabbitMQ has no concept of a message selector;与 JMS 不同,RabbitMQ 没有消息选择器的概念; you will get all messages.您将收到所有消息。

The canonical way to solve this issue is to use a different queue for each RK.解决这个问题的规范方法是为每个 RK 使用不同的队列。

bindingRoutingKey is meaningless when bindQueue is false and, in any case, all it does is specify which routing key to use when binding the queue to the exchange.bindingRoutingKey为 false 时, bindQueue没有意义,在任何情况下,它所做的只是指定在将队列绑定到交换器时使用哪个路由键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM