天天看點

kafka JsonParseException: Unrecognized token 'xxx': was expecting ('true', 'false' or 'null') 異常解決

ERROR WorkerSinkTask{id=local-file-sink-0} Task is being killed and will not recover until manually restarted (org.apache.kafka.connect.runtime.WorkerTask:178)

 按照 http://kafka.apachecn.org/quickstart.html 中文文檔做到 :

Step 7: 使用Kafka Connect來導入/導出資料

然後報了上面的異常

從kafka  JsonParseException: Unrecognized token 'xxx': was expecting ('true', 'false' or 'null') 可以知道是解析Json的時候異常

原因是我在:connect-file-sink.properties 裡配置的 topic:liucf-topic3

之前在 Step 6: 設定多代理叢集 中使用過connect-console-source.properties 通過控制台生産過消息,格式然後在topic:liucf-topic3中存在非json個的消息是以報上面的異常

kafka JsonParseException: Unrecognized token 'xxx': was expecting ('true', 'false' or 'null') 異常解決

解決辦法是,清除這個topic裡面的資料或者更換connect-file-sink.properties 裡配置的topics=新的topic;

然後重新:bin/connect-standalone.sh config/connect-standalone.properties config/connect-file-source.properties config/connect-file-sink.properties

connect-standalone.properties:

kafka JsonParseException: Unrecognized token 'xxx': was expecting ('true', 'false' or 'null') 異常解決

注意這之前要删除connect.offsets 不然建立的ConnectStandalone不能通過test.txt 生産消息到新的topic 因為它記錄還是上一次建立ConnectStandalone對應的topic。

删除後重新:

bin/connect-standalone.sh config/connect-standalone.properties config/connect-file-source.properties config/connect-file-sink.properties

就可以了