来自消费者群体的所有消费者都收到消息

时间:2016-05-10 22:58:01

标签: spring-cloud-stream

我编写了一个Spring云流应用程序来接收来自Kafka主题的消息。 我正在尝试设置使用者组,因此当我扩展我的应用程序时,只有一个应用程序实例从Kafka主题接收消息。

以下是我的application.yml spring: cloud: stream: bindings: orderTopic: group: orderGroup destination: orderTopic kafka: binder: brokers: 192.168.61.21 defaultBrokerPort: 9092 zkNodes: 192.168.61.21 defaultZkPort: 2181 我已将应用程序部署到云代工厂(pcfdev)并将应用程序的实例计数设置为2.当我向orderTopic主题发送订单时,我预计只有2个应用程序实例中的一个接收订单,但是,这两个应用程序实例接收如下所示的相同顺序 2016-05-10T16:33:46.42-0600 [APP/0] OUT Order Number 23 received. 2016-05-10T16:33:47.42-0600 [APP/1] OUT Order Number 24 received. 2016-05-10T16:33:47.42-0600 [APP/0] OUT Order Number 24 received. 2016-05-10T16:33:48.42-0600 [APP/1] OUT Order Number 25 received. 2016-05-10T16:33:48.42-0600 [APP/0] OUT Order Number 25 received. 2016-05-10T16:33:49.43-0600 [APP/1] OUT Order Number 26 received. 2016-05-10T16:33:49.43-0600 [APP/0] OUT Order Number 26 received.

你能帮忙吗

1 个答案:

答案 0 :(得分:0)

以下是您需要做的参考:http://docs.spring.io/spring-cloud-stream/docs/current-SNAPSHOT/reference/htmlsingle/#_instance_index_and_instance_count

Kafka活页夹需要该信息才能将分区正确分配给实例。

作为Spring Cloud Stream 1.1.0.M1工作的一部分,我们将升级到0.9 Kafka客户端,并在添加新实例时自动(重新)分区。