2016-08-03 158 views
0

我想为logstash创建一个conf文件,该文件从文件加载数据并将其发送到kafka。logstash输出到kafka - 消息中的主题数据

该文件采用json格式,并具有topicId。

这是我迄今为止..

input { 
    file { 
    path => "~/file1.json" 
    start_position => "beginning" 
    codec => "json" 
    } 
} 
filter { 
    json { 
     source => message 
    } 
} 
output { 
    kafka { 
    bootstrap_servers => "localhost" 
    codec => plain { 
     format => "%{message}" 
    } 
    topic_id => "???" 
    } 
} 

才能做到这一点?

问候, 伊

回答

1

是的,它可以做到的。

例如,如果该消息包含JSON像topic_id键:

"topicId": "topic1" 

然后在logstash卡夫卡输出插件:

output { 
    kafka { 
    bootstrap_servers => "localhost" 
    codec => plain { 
     format => "%{message}" 
    } 
    topic_id => "%{topicId}" 
    } 
}