basu76
basu76

Reputation: 481

spring kafka shutting down producer gracefully during runtime

We have a spring boot application, that uses spring-kafka. We want to disable kafka producer (kafkatemplate), when we update a config property. I have tried with conditional bean, and using applicationcontext refresh.

Is there a way to gracefully shutdown kafkaproducer with spring-kafka ?

Upvotes: 2

Views: 4949

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

You can call destroy() on the DefaultKafkaProducerFactory and it will close the (singleton) producer, but the next time some code calls createProducer() another one will be created; there's currently no way to prevent that. You would need to subclass the factory and throw an exception when you don't want a producer to be created.

Upvotes: 1

Related Questions