1.需求:
測試同一個消費者組中的消費者,同一時刻只能有一個消費者消費。
2.案例實操
(1)在hadoop2、hadoop3上修改/opt/module/kafka-2.11/config/consumer.properties配置文件中的group.id屬性爲任意組名。
vi consumer.properties
group.id=movle
(2)再hadoop3、hadoop4上分別啓動消費者
./bin/kafka-console-consumer.sh --bootstrap-server hadoop2:9092 --topic topic0519 --consumer.config config/consumer.properties
./bin/kafka-console-consumer.sh --bootstrap-server hadoop2:9092 --topic topic0519 --consumer.config config/consumer.properties
(3)在hadoop2上啓動生產者
bin/kafka-console-producer.sh --broker-list hadoop2:9092 --topic topic0519
>hello world
(4)查看bigdata11和bigdata12的接收者。
同一時刻只有一個消費者接收到消息。