2016-09-29 90 views
0

我已经建立了一个生产者春天云流app和kafka作为活页夹。这里是application.yml:春天云流kafka

spring: 
cloud: 
    stream: 
    instanceCount : 1 
    bindings: 
     output: 
     destination: topic-sink 
     producer: 
      partitionSelectorClass: com.partition.CustomPartition 
      partitionCount: 1   
... 

我有两个实例(同一个应用程序运行在单个jvm上)作为消费者。这里是application.yml:

spring: 
cloud: 
    stream: 
    bindings: 
     input: 
     destination: topic-sink 
     group: hdfs-sink 
     consumer: 
      partitioned: true 
... 

我卡夫卡组的理解是,消息将只进行一次消费,对于那些消费者在同一组。比方说,如果生产者应用程序生成消息A,B并且同一组中有两个消费者应用程序,则消息1将读取消息A,消费者2将读取消息B,C.但是,我的消费者正在消费相同消息。我的假设错了吗?

+0

与消费者团体的想法是,该组内所有的消费者将消费从给定主题的所有事件。但是,如果消费者的数量多于该主题的分区数,那么N个消费者(其中N是#consumers - #分区)将无所作为。 – Arek

回答

0

我得到了解决方案,谢谢Arek。对于1个分区和1个消费者。 我在春云流应用程序中共享生产者\消费者的解决方案。 监制:

spring: cloud: stream: instanceCount : 1 bindings: output: destination: topic-sink producer: partitionSelectorClass: com.partition.CustomPartition partitionCount: 1
消费者:

spring: cloud: stream: instanceIndex: 0 #between 0 and instanceCount - 1 instanceCount: 1 bindings: input: destination: topic-sink group: hdfs-sink consumer: partitioned: true
kafka: binder: autoAddPartitions: true