[英]How to get custom key value in the logstash kafka input?
在我的制作人中,我在標題中添加了一些自定義鍵。 使用 logstash 我需要獲取有效負載,此外我需要讀取我的密鑰的值。
生產者代碼:
kafkaTemplate
.send(
MessageBuilder.withPayload(myPayload)
.setHeader(KafkaHeaders.TOPIC, myTopic)
.setHeader("my-key1", "test-key1") // custom keys
.setHeader("my-key2", "test-key2") // custom keys
.build())
Logstash 配置
input{
kafka{
//kafka connection details
decorate_events => true
}
}
filter{
mutate => { add_field => { "kafka-topic" => "%{[@metadata][kafka][topic]}" } // this is working
mutate => { add_field => { "custom-key" => "%{[my-key1]}" } // this is not working
}
output{
// store the payload on ES index, _id = my-key1
}
我無法讀取我的自定義密鑰。 我錯過了配置中的任何內容嗎?
在最近的 Logstash 版本中,您可以設置decorate_events => "extended"
(true 表示基本),然后使用以下方法獲取標頭:
%{[@metadata][kafka][headers][my-key1]}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.