Reputation: 157
I have a consumer in spring boot application, using spring kafka library. I want to set tenancy context per consumer thread i.e. want to call a method on each thread once it is created (just once per thread when created). Currently, I have added it in listner which has @KafkaListner annotation on method, but it calls everytime it polls and does the processing of each record. I want to call this method once when consumer thread is started. Could you please help me here, if we have any such thing.
Upvotes: 0
Views: 1372
Reputation: 174514
Add an event listener to listen for a consumer started event. It is called on the same thread (by default).
https://docs.spring.io/spring-kafka/docs/current/reference/html/#events
https://docs.spring.io/spring-kafka/docs/current/reference/html/#event-consumption
Upvotes: 1