背景
在华为云服务器上跑了 zookeeper 和 kafka 的 broker,想内外网分流,重点就是做不到从外网去消费,比如用自己的 windows 笔记本去消费。
配置 server.properties 的 listener
为 broker 所在机子的的内网 IP 后,终于能 start 了:
listener=PLAINTEXT://192.168.0.154:9092
zookeeper 查看 kafka broker 的地址:
get /brokers/ids/0
{
"features":{
},"listener_security_protocol_map":{
"PUBLIC":"PLAINTEXT"},"endpoints":["PUBLIC://192.168.0.154:9092"],"jmx_port":-1,"port":9092,"host":"192.168.0.154","version":5,"timestamp":"1686651266529"}
地址是 “endpoints”:[“PUBLIC://192.168.0.154:9092”]
从 broker 机子的本地创建 topic:
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --topic test0
结果疯狂滚屏:
workClient)
[2023-06-13 18:21:48,162] WARN [AdminClient clientId=adminclient-1] Connection to node -1 (localhost/127.0.1.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2023-06-13 18:21:49,266] WARN [AdminClient clientId=adminclient-1] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
换个姿势创建:
bin/kafka-topics.sh --create --bootstrap-server 192.168.0.154:9092 --topic test0
成功了:
broker 本机来 produce。
换同网段机子 192.168.0.28 来消费:
外网 windows 去消费:
D:\Programs\MQ\kafka\kafka_2.12-3.2.3\bin\windows>kafka-console-consumer.bat --topic test0 --from-beginning --bootstrap-server 121.37.xx.xxx:9092
[2023-06-13 18:44:40,678] WARN [Consumer clientId=console-consumer, groupId=console-consumer-76813] Connection to node 0 (/192.168.0.154:9092) could not be established. Broker may not be avail