春季云流-消费群约束

时间:2019-02-24 08:58:31

标签: spring-boot spring-cloud kafka-consumer-api spring-cloud-stream spring-kafka

我的使用者绑定到匿名使用者组,而不是我指定的使用者组。

spring:
  cloud:
    stream:
      kafka:
        binder:
          brokers: localhost
          defaultBrokerPort: 9092
          zkNodes: localhost
          defaultZkPort: 2181
        bindings:
          inEvent:
            group: eventin
            destination: event
          outEvent:
            group: eventout
            destination: processevent

我的Spring Boot应用程序

@SpringBootApplication
@EnableBinding(EventStream.class)
public class ConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }
    @StreamListener(value = "inEvent")
    public void getEvent(Event event){
        System.out.println(event.name);
    }
}

我的输入输出通道界面

public interface EventStream {
    @Input("inEvent")
    SubscribableChannel inEvent();
    @Output("outEvent")
    MessageChannel outEvent();
}

我的控制台日志-

  

:在3.233秒内启动ConsumerApplication(JVM运行4.004)   :[消费者clientId = consumer-3,groupId = anonymous.0d0c87d6-ef39-4bfe-b475-4491c40caf6d] 已发现   小组协调员singh:9092(编号:2147483647机架:空)       :[Consumer clientId = consumer-3,groupId = anonymous.0d0c87d6-ef39-4bfe-b475-4491c40caf6d]吊销   先前分配的分区[]       :分区被撤销:[]       :[Consumer clientId = consumer-3,groupId = anonymous.0d0c87d6-ef39-4bfe-b475-4491c40caf6d](重新)加入   组       :成功[消费者clientId = consumer-3,groupId = anonymous.0d0c87d6-ef39-4bfe-b475-4491c40caf6d]   第1代加入的小组       :[Consumer clientId = consumer-3,groupId = anonymous.0d0c87d6-ef39-4bfe-b475-4491c40caf6d]新设置   分配的分区[inEvent-0]       :[Consumer clientId = consumer-3,groupId = anonymous.0d0c87d6-ef39-4bfe-b475-4491c40caf6d]重置   分区inEvent-0的偏移量为偏移量2。       :分配的分区:[inEvent-0]

1 个答案:

答案 0 :(得分:2)

group属性不能在kafka树中。 一定是这样的:

我的使用者绑定到匿名使用者组,而不是我指定的使用者组。

spring:
  cloud:
    stream:
       bindings:
          inEvent:
            group: eventin
            destination: event

在文档中查看更多信息:http://cloud.spring.io/spring-cloud-static/spring-cloud-stream/2.1.1.RELEASE/single/spring-cloud-stream.html#consumer-groups

group是一个公共属性,因此独立于活页夹实现而相同。 kafka适用于Apache Kafka的特定属性,在其绑定器实现级别上公开。

相关问题