kafka启动配置如下
listeners=PLAINTEXT://localhost:9092
advertised.listeners未配
/etc/hosts文件里面同时配置了(ipv4和ipv6的localhost):
127.0.0.1 localhost
::1 localhost
消费者程序运行在ipv4环境中,且消费一直正常,但是时不时会弹出一个ipv6的connection refused的报错(不影响正常消费)
%3|1677748565.071|FAIL|rdkafka#consumer-6| [thrd:GroupCoordinator]: GroupCoordinator: localhost:9092: Connect to ipv6#[::1]:9092 failed: Connection refused (after 0ms in state CONNECT)
% ERROR CALLBACK: rdkafka#consumer-6: Local: Broker transport failure: GroupCoordinator: localhost:9092: Connect to ipv6#[::1]:9092 failed: Connection refused (after 0ms in state CONNECT), error code [-195]
虽然不影响业务正常运行,但是是什么原因呢?怎么可以避免?循环报错很烦
librdkafka是支持python客户端的底层C客户端,它使用系统解析器来解析broker主机名。在某些系统上,特别是OSX系统中,/etc/hosts中的localhost条目会解析为IPv4和IPv6地址,因此librdkafka会以循环方式尝试连接到主机名解析的所有地址。
可以设置
broker.address.family
为v4
。参考来自:https://docs.confluent.io/2.0.1/clients/librdkafka/CONFIGURATION_8md.html
你的答案