我可以使用 Spring Cloud Stream 绑定到多个消费者组吗? [英] Can I bind to multiple consumer groups with Spring Cloud Stream?
问题描述
我正在编写一个处理事件消息的应用程序(发布到主题file-upload-completed
).我有多个端点应该使用这些消息(metadata-reader
和 quota-checker
),出于实用的原因,我想将这些端点一起部署在一个聚合包中.
I am writing an application that will process event messages (posted to the topic file-upload-completed
). I have multiple endpoints that should consume these messages (metadata-reader
and quota-checker
), and for pragmatic reasons I would like to deploy these endpoints together in an aggregated package.
使用 Spring Cloud Stream,我可以使用 spring.cloud.stream.bindings.file-upload-completed.group=metadata-reader
为第一个端点设置使用者组;我也想处理 quota-check
组下的消息,但基于属性的配置只允许每个消息队列绑定一个消费者组.
With Spring Cloud Stream, I could use spring.cloud.stream.bindings.file-upload-completed.group=metadata-reader
to set the consumer group for the first endpoint; I would also like to process messages under the quota-check
group, but the property-based configuration only permits one consumer group binding per message queue.
有没有办法配置 Spring Cloud Stream 以便我可以绑定到同一应用程序中多个消费者组下的单个消息队列?
Is there a way to configure Spring Cloud Stream so that I can bind to a single message queue under multiple consumer groups in the same application?
推荐答案
但基于属性的配置只允许每个消息队列绑定一个消费者组.
but the property-based configuration only permits one consumer group binding per message queue.
按消息队列是指按绑定吗?
by per message queue, do you mean, per-binding?
此外,当您指定属性 spring.cloud.stream.bindings.file-upload-completed.group=metadata-reader
时,file-upload-completed
这里表示绑定的目标名称(例如:频道名称),您可以定义任意数量的频道及其与绑定到特定目的地的特定消费者组的绑定(主题:file-upload-completed
)
Also, when you specify the property spring.cloud.stream.bindings.file-upload-completed.group=metadata-reader
, the file-upload-completed
here means the bound target name (ex: the channel name) and you can define as many number of channels and their bindings with the specific consumer group that bound to a specific destination (topic: file-upload-completed
)
spring.cloud.stream.bindings.mychannel1.destination=file-upload-completed
spring.cloud.stream.bindings.mychannel1.group=metadata-reader
spring.cloud.stream.bindings.mychannel2.destination=file-upload-completed
spring.cloud.stream.bindings.mychannel2.group=metadata-reader
有了上面的配置,就可以进行join等操作了,像这样:
With the above configuration, you can perform operations such as join etc., something like this:
@StreamListener
public void receive(@Input(Processor.INPUT) SubscribableChannel input1,
@Input("mychannel2") SubscribableChannel input2) {
// perform operations (join etc.,)
}
这篇关于我可以使用 Spring Cloud Stream 绑定到多个消费者组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!