无法消费Apache Kafka消息:NotCoordinatorForGroupError问题求助
本地Kafka消费失败排查:NotCoordinatorForGroupError问题
我是Kafka新手,本地部署Kafka后能正常向Topic写入消息,但无法消费。通过偏移量工具确认消息已存在:
~/kafka/bin/kafka-topics.sh --create --replication-factor 1 --bootstrap-server localhost:9092 --partitions 1 --topic Topic1 Created topic Topic1. ~/kafka/config$ echo "Hello, World" | ~/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic Topic1 > /dev/null ~/kafka/config$ ../bin//kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic Topic1 --time -1 Topic1:0:1 ~/kafka/config$ ../bin//kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic Topic1 --time -2 Topic1:0:0 ~/kafka/config$ ~/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic Topic1 --from-beginning (blank)
尝试编写Python脚本消费时,重复输出以下日志:
DEBUG:kafka.coordinator:Sending group coordinator request for group test-grp-1 to broker 0 DEBUG:kafka.protocol.parser:Sending request GroupCoordinatorRequest_v0(consumer_group='test-grp-1') DEBUG:kafka.conn:<BrokerConnection node_id=0 host=localhost:9092 <connected> [IPv4 ('127.0.0.1', 9092)]> Request 5: GroupCoordinatorRequest_v0(consumer_group='test-grp-1') DEBUG:kafka.protocol.parser:Received correlation id: 5 DEBUG:kafka.protocol.parser:Processing response GroupCoordinatorResponse_v0 DEBUG:kafka.conn:<BrokerConnection node_id=0 host=localhost:9092 <connected> [IPv4 ('127.0.0.1', 9092)]> Response 5 (1.7061233520507812 ms): GroupCoordinatorResponse_v0(error_code=0, coordinator_id=0, host='localhost', port=9092) DEBUG:kafka.coordinator:Received group coordinator response GroupCoordinatorResponse_v0(error_code=0, coordinator_id=0, host='localhost', port=9092) DEBUG:kafka.cluster:Updating coordinator for test-grp-1: GroupCoordinatorResponse_v0(error_code=0, coordinator_id=0, host='localhost', port=9092) INFO:kafka.cluster:Group coordinator for test-grp-1 is BrokerMetadata(nodeId='coordinator-0', host='localhost', port=9092, rack=None) INFO:kafka.coordinator:Discovered coordinator coordinator-0 for group test-grp-1 INFO:kafka.coordinator:(Re-)joining group test-grp-1 DEBUG:kafka.coordinator:Sending JoinGroup (JoinGroupRequest_v2(group='test-grp-1', session_timeout=10000, rebalance_timeout=300000, member_id='', protocol_type='consumer', group_protocols=[(protocol_name='range', protocol_metadata=b'\x00\x00\x00\x00\x00\x01\x00\x06Topic1\x00\x00\x00\x00'), (protocol_name='roundrobin', protocol_metadata=b'\x00\x00\x00\x00\x00\x01\x00\x06Topic1\x00\x00\x00\x00')])) to coordinator coordinator-0 DEBUG:kafka.protocol.parser:Sending request JoinGroupRequest_v2(group='test-grp-1', session_timeout=10000, rebalance_timeout=300000, member_id='', protocol_type='consumer', group_protocols=[(protocol_name='range', protocol_metadata=b'\x00\x00\x00\x00\x00\x01\x00\x06Topic1\x00\x00\x00\x00'), (protocol_name='roundrobin', protocol_metadata=b'\x00\x00\x00\x00\x00\x01\x00\x06Topic1\x00\x00\x00\x00')]) DEBUG:kafka.conn:<BrokerConnection node_id=coordinator-0 host=localhost:9092 <connected> [IPv4 ('127.0.0.1', 9092)]> Request 6: JoinGroupRequest_v2(group='test-grp-1', session_timeout=10000, rebalance_timeout=300000, member_id='', protocol_type='consumer', group_protocols=[(protocol_name='range', protocol_metadata=b'\x00\x00\x00\x00\x00\x01\x00\x06Topic1\x00\x00\x00\x00'), (protocol_name='roundrobin', protocol_metadata=b'\x00\x00\x00\x00\x00\x01\x00\x06Topic1\x00\x00\x00\x00')]) DEBUG:kafka.protocol.parser:Received correlation id: 6 DEBUG:kafka.protocol.parser:Processing response JoinGroupResponse_v2 DEBUG:kafka.conn:<BrokerConnection node_id=coordinator-0 host=localhost:9092 <connected> [IPv4 ('127.0.0.1', 9092)]> Response 6 (1.4925003051757812 ms): JoinGroupResponse_v2(throttle_time_ms=0, error_code=16, generation_id=-1, group_protocol='', leader_id='', member_id='', members=[]) WARNING:kafka.coordinator:Marking the coordinator dead (node coordinator-0) for group test-grp-1: [Error 16] NotCoordinatorForGroupError. DEBUG:kafka.coordinator:Attempt to join group test-grp-1 failed due to obsolete coordinator information: NotCoordinatorForGroupError
排查与解决方案
1. 重启Kafka与ZooKeeper(若使用)
NotCoordinatorForGroupError常因集群元数据不一致导致,重启服务可强制同步元数据:
# 停止Kafka ~/kafka/bin/kafka-server-stop.sh # 停止ZooKeeper ~/kafka/bin/zookeeper-server-stop.sh # 先启动ZooKeeper ~/kafka/bin/zookeeper-server-start.sh ~/kafka/config/zookeeper.properties & # 等待几秒后启动Kafka ~/kafka/bin/kafka-server-start.sh ~/kafka/config/server.properties &
2. 清理异常消费者组元数据
消费者组可能残留错误的协调器绑定信息,删除后重新创建会话:
~/kafka/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group test-grp-1
执行后重新运行消费者脚本或控制台消费者。
3. 检查Kafka网络配置
打开~/kafka/config/server.properties,确认以下配置:
listeners:设为PLAINTEXT://localhost:9092或PLAINTEXT://0.0.0.0:9092,确保消费者能访问到brokeradvertised.listeners:本地环境可注释掉或与listeners保持一致,避免地址不匹配导致协调器识别错误
修改配置后重启Kafka生效。
4. 测试控制台消费者
指定新的消费者组运行控制台消费者,排除旧组的影响:
~/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic Topic1 --from-beginning --group test-grp-2
内容的提问来源于stack exchange,提问作者Ankitha N
相关产品推荐
相关产品推荐

