0
votes

A potential source of serious bugs would be if a message is sent while the producer is closed. This causes my application to hang indefinitely.

I'd like to handle this case appropriately by raising an error, but there doesn't seem to be a method in the API for checking if a producer is closed.

https://kafka.apache.org/090/javadoc/index.html?org/apache/kafka/clients/producer/KafkaProducer.html

Is there any way to do this?

1

1 Answers

0
votes

You could make calls to producer in asynchronous way (aka in a different thread), so that your main program will continue its execution. Then you can add some time measurement around the producer thread, and raise an exception, print error to log, store the unsent message to DB etc. and kill the thread.