Spring Kafka 消费者/监听器组

tap*_*toe 6 apache-kafka spring-kafka

在消费者处指定组有什么区别

spring.kafka.consumer.group-id
Run Code Online (Sandbox Code Playgroud)

与在 @KafkaListener 指定?

@KafkaListener(topic="test", group = "test-grp")
Run Code Online (Sandbox Code Playgroud)

Gar*_*ell 4

请参阅该group属性的 javadoc;和卡夫卡没关系group.id...

/**
 * If provided, the listener container for this listener will be added to a bean
 * with this value as its name, of type {@code Collection<MessageListenerContainer>}.
 * This allows, for example, iteration over the collection to start/stop a subset
 * of containers.
 * @return the bean name for the group.
 */
Run Code Online (Sandbox Code Playgroud)

这已containerGroup在 1.3/2.0 中重命名。

这些发行版本还提供...

/**
 * 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 {@link #groupId() groupId} is not provided, use the {@link #id() id} (if
 * provided) as the {@code group.id} property for the consumer. Set to false, to use
 * the {@code group.id} from the consumer factory.
 * @return false to disable.
 * @since 1.3
 */
boolean idIsGroup() default true;
Run Code Online (Sandbox Code Playgroud)

以前,您需要为每个侦听器提供一个容器工厂/消费者工厂;这些允许您使用一个工厂实例并覆盖group.id.