KafkaListener Spring Boot中group id、Client id和id的区别

Am1*_*3zA 5 apache-kafka spring-boot spring-kafka

我开始工作与Spring启动2和Spring卡夫卡,我不太明白什么是之间的区别group idClient id以及id inKafkaListener接口。
我知道Kafka经纪人使用组ID来管理同一组中的多个消费者,但其他人呢?设置它们有什么好处?我在哪里可以看到设置或不设置它们的效果?

基于他们的 java 文档:

/**
     * The unique identifier of the container managing for this endpoint.
     * <p>If none is specified an auto-generated one is provided.
     * @return the {@code id} for the container managing for this endpoint.
     * @see org.springframework.kafka.config.KafkaListenerEndpointRegistry#getListenerContainer(String)
     */
String id() default "";

/**
 * Override the {@code group.id} property for the consumer factory with this value
 * for this listener only.
 * @return the group id.
 * @since 1.3
 */
String groupId() default "";

/**
 * When provided, overrides the client id property in the consumer factory
 * configuration. A suffix ('-n') is added for each container instance to ensure
 * uniqueness when concurrency is used.
 * @return the client id prefix.
 * @since 2.1.1
 */
String clientIdPrefix() default "";
Run Code Online (Sandbox Code Playgroud)

Art*_*lan 7

你的groupId理解是正确的。

id就像Spring框架的一个bean的名字。然而,这KafkaListenerEndpointRegistry仅在边界中使用。所以,如果你需要在特定的生命周期的控制KafkaListenerContainer对于所提到的创建@KafkaListener,你需要注入KafkaListenerEndpointRegistry和使用中提到getListenerContainer()的适当的id

clientIdPrefixKafka Consumer确切client.id属性的反映:

发出请求时传递给服务器的 id 字符串。这样做的目的是通过允许将逻辑应用程序名称包含在服务器端请求日志记录中,从而能够跟踪请求源,而不仅仅是 ip/端口。