只要增加
advertised.listeners=PLAINTEXT://服务器外网ip:9092
这项配置,就会上面的错误
在服务器上用命令收发消息都正常的。命令:
./kafka-console-consumer.sh --bootstrap-server 172.17.108.105:9092 --topic testq --from-beginning
刚看到springboot工程启动日志,kafka服务返回的地址是:172.17.108.105:9092。说明,kafka服务返回的地址是个内网地址,所有连接不上。怎样才能返回外网连接的地址?
[Consumer clientId=consumer-4, groupId=testq] Group coordinator 172.17.108.105:9092 (id: 2147483647 rack: null) is unavailable or invalid, will attempt rediscovery
按spring的文档,kafka_2.11-2.1.0 可以使用spring-kafka:1.0.2 的版本,所以应该不是版本的问题。
服务启动日志看:先报了下面的错误,
[Consumer clientId=consumer-10, groupId=testq] Error while fetching metadata with correlation id 2 : {testq=LEADER_NOT_AVAILABLE}
之后就周期报下面的错误:
10:03:40.851 [org.springframework.kafka.KafkaListenerEndpointContainer#0-7-C-1] WARN o.apache.kafka.clients.NetworkClient :
[Consumer clientId=consumer-8, groupId=testq] Connection to node 0 could not be established. Broker may not be available.
10:03:40.885 [org.springframework.kafka.KafkaListenerEndpointContainer#0-3-C-1] WARN o.apache.kafka.clients.NetworkClient :
[Consumer clientId=consumer-4, groupId=testq] Connection to node 0 could not be established. Broker may not be available.
10:03:41.089 [org.springframework.kafka.KafkaListenerEndpointContainer#0-6-C-1] WARN o.apache.kafka.clients.NetworkClient :
[Consumer clientId=consumer-7, groupId=testq] Connection to node 0 could not be established. Broker may not be available.
10:03:41.416 [org.springframework.kafka.KafkaListenerEndpointContainer#0-1-C-1] WARN o.apache.kafka.clients.NetworkClient :
[Consumer clientId=consumer-2, groupId=testq] Connection to node 0 could not be established. Broker may not be available.