2

I want to create a conf file for logstash that loads data from a file and send it to kafka.

the file is in json format and has the topicId in it.

This is what I have so far..

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 =>  "???"
  }
}

can this be done?

Regards, Ido

1 Answer 1

3

Yes it can be done.

For example if the message json contains a topic_id key like:

"topicId": "topic1"

Then in logstash kafka output plugin:

output {
  kafka { 
    bootstrap_servers => "localhost"
    codec => plain {
        format => "%{message}"
    }
    topic_id =>  "%{topicId}"
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.