深入浅出理解kafka原理系列之:单播消息和多播消息
一、单播消息
- 在一个kafka的topic中,启动两个消费者,如果多个消费者在同一个消费组,那么只有一个消费者可以收到订阅的topic中的消息。
- 同一个消费组中只能有一个消费者收到一个topic中的消息。
./kafka-console-consumer.sh --bootstrap-server bigdata1:9092 --topic test --from-beginning --consumer-property group.id=testgroup1
二、多播消息
- 不同的消费组订阅同一个topic,那么不同的消费组中只有一个消费者能收到消息。
- 多个消费者组中的多个消费者收到了同一个消息。
./kafka-console-consumer.sh --bootstrap-server bigdata1:9092 --topic test --from-beginning --consumer-property group.id=testgroup1
./kafka-console-consumer.sh --bootstrap-server bigdata1:9092 --topic test --from-beginning --consumer-property group.id=testgroup2