我在Kafka有一个标题为newtest
的主题,有三条消息:
Hello
Is anybody out there
Can you hear me
...我有一个连接作业的配置:
{
"name":"connect-test-9",
"config":
{
"connector.class":"FileStreamSink",
"file":"connector-test",
"topics":"newtest",
"name":"connect-test-9",
"value.converter":"org.apache.kafka.connect.storage.StringConverter",
"value.converter.schemas.enable":"false",
"key.converter":"org.apache.kafka.connect.storage.StringConverter",
"key.converter.schemas.enable":"false",
"transforms":"Hoist, AddTimestamp",
"transforms.Hoist.type":"org.apache.kafka.connect.transforms.HoistField$Value",
"transforms.Hoist.field":"line",
"transforms.AddTimestamp.type":"org.apache.kafka.connect.transforms.InsertField$Value",
"transforms.AddTimestamp.timestamp.field":"Timestamp"
}
}
我在文件connector-test
中收到以下输出:
Struct{line=Hello,Timestamp=Mon Mar 12 14:50:34 PDT 2018}
Struct{line=Is anybody out there,Timestamp=Mon Mar 12 14:50:44 PDT 2018}
Struct{line=Can you hear me,Timestamp=Mon Mar 12 14:50:52 PDT 2018}
我想得到这个:
{"line":"Hello","Timestamp":"Mon Mar 12 14:50:34 PDT 2018"}
{"line":"Is anybody out there","Timestamp":"Mon Mar 12 14:50:44 PDT 2018"}
{"line":"Can you hear me","Timestamp":"Mon Mar 12 14:50:52 PDT 2018"}
我尝试过更改value.converter,没有好处(解析异常)。我还有另一个主题,其中消息已经是Json,并且解析在那里成功,我可以添加一个没有Hoist的Timestamp。但我的输出是非Json格式{key1=value1,key2=value2}
。
我能以任何方式获得正确的JSON输出吗?
这是我看到的解析异常:
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Can': was expecting ('true', 'false', or 'null')