【问题标题】:Spring Kafka Consumer/Listener GroupSpring Kafka 消费者/听众组
【发布时间】:2017-12-21 04:50:35
【问题描述】:

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

spring.kafka.consumer.group-id

vs 在@KafkaListener 指定?

@KafkaListener(topic="test", group = "test-grp")

【问题讨论】:

    标签: apache-kafka spring-kafka


    【解决方案1】:

    查看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

    【讨论】:

    • 谢谢@Gary Russel。我已经浏览了文档,但不清楚。 “以前,您需要为每个侦听器创建一个容器工厂/消费者工厂;这些允许您使用一个工厂实例并覆盖 group.id。”这个澄清帮助了我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 2018-11-08
    • 2018-10-13
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    • 2017-10-16
    相关资源
    最近更新 更多