Can someone post an example or help how i can use KafkaItemWriter to write java objects into non-default topic. Just like in SpringKafka we use KafkaTemplate.send(topicName, user) is there a way for kafkaItemWriter also? I do not want to write to default topic configured through properites file like spring.kafka.template.default-topic=topicName. In my springBatch job i want to run to different batch jobs and like to write into two different topics.
Asked
Active
Viewed 409 times
1
-
`In my springBatch job i want to run to different batch jobs and like to write into two different topics.`: If you are going to use two different jobs, why don't you use two different writers each one configured for a separate topic? – Mahmoud Ben Hassine Sep 18 '20 at 09:27
-
Yes, i will write two different writers each one configured to two separate topics. I figured a way out to set topic name into writer using KafkaTemplate.setDefaultTopic method. Now in another writer i will set diff topic name. Thanks, I have one more question, in my requirement for two spring batch jobs, i have one reader, processor and writer and for another job, i want to use same reader but different processor and different writer because in both jobs reader is going to read data from same table from db and i do not want to make another call for reading same data. – user4005166 Sep 18 '20 at 21:45
1 Answers
0
I’m not sure this is what you want or not. But KafkaTemplate has method “setDefaultTopic” (https://docs.spring.io/spring-kafka/api/org/springframework/kafka/core/KafkaTemplate.html#setDefaultTopic(java.lang.String))
I think you can change default topic what you want by using setDefaultTopic before call KafakItemWriter step.

JinHyup Kim
- 11
- 1