1. 程式人生 > >springboot整合kafka發訊息報Exception thrown when sending a message with key= and payload='1' to topic test

springboot整合kafka發訊息報Exception thrown when sending a message with key= and payload='1' to topic test

本地環境 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

錯誤排查:

  1.     伺服器防火牆已關閉,本地telnet連線9092埠沒問題
  2.     kafka配置檔案 listeners=PLAINTEXT://{內網ip}:9092
  3.     將專案日誌級別調製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 日誌級別下會列印心跳日誌