Spring Kafka消费者/听众组

问题描述 投票:1回答:1

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

spring.kafka.consumer.group-id

vs在@KafkaListener中指定?

@KafkaListener(topic="test", group = "test-grp")
apache-kafka spring-kafka
1个回答
2
投票

有关group属性的信息,请参阅javadocs;它与kafka 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.
 */

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

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

/**
 * 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;

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

© www.soinside.com 2019 - 2024. All rights reserved.