我开始使用SpringBoot2和SpringKafka,我不太明白它们之间的区别 group id
, Client id
,和 id in
在 KafkaListener
接口。
我知道kafka代理使用group 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 "";
1条答案
按热度按时间xkrw2x1b1#
你的
groupId
理解是正确的。这个
id
类似于spring框架中的bean名称。然而,这一个是用在KafkaListenerEndpointRegistry
仅限边界。因此,如果您需要对特定的KafkaListenerContainer
为所提及的@KafkaListener
,你需要注射KafkaListenerEndpointRegistry
使用上面提到的getListenerContainer()
对于适当的id
.这个
clientIdPrefix
是准确的client.id
Kafka消费者财产:发出请求时要传递给服务器的id字符串。这样做的目的是通过允许在服务器端请求日志记录中包含逻辑应用程序名称,从而能够跟踪ip/端口以外的请求源。