本地环境 springboot集成kafka发消息报错Exception thrown when sending a message with key='' and payload='1' to topic test
org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s) for test-0 due to 30049 ms has passed since batch creation plus linger time
错误排查:
- 服务器防火墙已关闭,本地telnet连接9092端口没问题
- kafka配置文件 listeners=PLAINTEXT://{内网ip}:9092
- 将项目日志级别调制DEBUG 发现启动过程报错
Connection with /{内网ip} disconnected
java.net.ConnectException: Connection timed out: no further information
Initiating connection to node 0 at {内网ip}:9092.
由此可见错误原因是本地无法访问服务器内网ip导致
解决办法:
修改kafka配置文件server.properties
listeners=PLAINTEXT://{内网ip}:9092
advertised.listeners=PLAINTEXT://{外网ip}:9092
重新启动本地项目,发送消息成功,并且DEBUG 日志级别下会打印心跳日志