我是Logstash和Avro的初学者。 我们正在建立一个以logstash作为kafka队列生产者的系统。但是,我们遇到了由Logstash产生的avro序列化事件不能被apache提供的avro-tools jar(版本1.8.2)解码的问题。此外,我们注意到Logstash和avro-tools的序列化输出不同。Logstash avro输出不能被apache解码avro-tools
我们有以下设置:
- logstash版本5.5
- logstash Avro的编解码器版本3.2.1
- 卡夫卡版本0.10.1
- Avro的工具罐子版本1.8.2
作为示例,考虑以下模式:
{
"name" : "avroTestSchema",
"type" : "record",
"fields" : [ {
"name" : "testfield1",
"type" : "string"
},
{
"name" : "testfield2",
"type" : "string"
}
]
}
和以下JSON字符串:
{"testfield1":"somestring","testfield2":"anotherstring"}
当使用Logstash序列化。 Logstash配置文件:
input {
stdin {
codec => json
}
}
filter {
mutate {
remove_field => ["@timestamp", "@version"]
}
}
output {
kafka {
bootstrap_servers => "localhost:9092"
codec => avro {
schema_uri => "/path/to/TestSchema.avsc"
}
topic_id => "avrotestout"
}
stdout {
codec => rubydebug
}
}
输出(使用cat):
FHNvbWVzdHJpbmcaYW5vdGhlcnN0cmluZw==
当使用Avro的工具序列化。 命令:
java -jar avro-tools-1.8.2.jar jsontofrag --schema-file TestSchema.avsc message.json
输出
somestringanotherstring
命令:
java -jar avro-tools-1.8.2.jar fromjson --schema-file TestSchema.avsc message.json
输出:
Objavro.codenullavro.schema▒{"type":"record","name":"avroTestSchema","fields":[{"name":"testfield1","type":"string"},{"name":"testfield2","type":"string"}]}▒▒▒▒&70▒▒Hs▒U2somestringanotherstring▒▒▒▒&70▒▒Hs▒U
所以我们的问题是: 我们如何配置Logstash使输出变得与apache avro-tools jar兼容?
更新:我们发现生成的avro输出的logstash是base64编码的。但是找不到这种情况,以及如何使其兼容工具