这里的监听ip:端口如果写了localhost:9092,则java端写:
//连接kafka
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"192.168.1.207:9092");
如果发消息一直卡在连接,则说明连接不上,需要修改上图中的:
############################# Socket Server Settings #############################
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://:9092
# Hostname and port the broker will advertise to producers and consumers. If not set,
# it uses the value for "listeners" if configured. Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
advertised.listeners=PLAINTEXT://192.168.1.207:9092
把相应的配置项:advertised.listeners
更改为 具体的ip和端口号,或者java端和服务器端都用域名映射