多个消费者监听消费同一个Topic主题
一、需求介绍
有一个Topic:hw_data 有3个分区 3个副本
组:hw-data-group
将这个主题的消息分发给两个(或者多个)消费者消费,(不能消费相同的消息)

二、@kafkaListener注解

@Target({
ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@MessageMapping
@Documented
@Repeatable(KafkaListeners.class)
public @interface KafkaListener {
/**
* 消费者的id,当GroupId没有被配置的时候,默认id为GroupId
*/
String id() default "";
/**
* 监听容器工厂,当监听时需要区分单数据还是多数据消费需要配置containerFactory 属性
*/
String containerFactory() default "";
/**
* 需要监听的Topic,可监听多个,和 topicPattern 属性互斥
*/
String[] topics() default {
};
/**
* 需要监听的Topic的正则表达。和 topics,topicPartitions属性互斥
*/
String topicPattern() default "";
/**
* 可配置更加详细的监听信息,必须监听某个Topic中的指定分区,或者从offset为200的偏移量开始监听,可配置该参数, 和 topicPattern 属性互斥
*/
TopicPartition[] topicPartitions()

最低0.47元/天 解锁文章
2572

被折叠的 条评论
为什么被折叠?



