confluent-kafka-python icon indicating copy to clipboard operation
confluent-kafka-python copied to clipboard

Make producer callback optional

Open wyfo opened this issue 3 years ago • 1 comments

Question

As mentioned in #885, there is always a producer callback registered, allowing to execute on_delivery when provided. I doesn't know Kafka very well, but I've understand that we have to call Producer.poll after Producer.produce because of the callback registration. However, when on_delivery is never used at all, then calling poll would not be mandatory.

Could it be a good idea to add a no_callback boolean parameter to Producer which would prevent the callback to be added? As a side effect, when no_callback=False, using on_delivery by mistake should raise an error.

wyfo avatar Feb 12 '22 00:02 wyfo

Hi @wyfo, thanks for asking.

-> However, when on_delivery is never used at all, then calling poll would not be mandatory. Even though don't set the deliver callback, you still need to call the poll() because the python client sets a delivery callback internally.

-> Could it be a good idea to add a no_callback boolean parameter to Producer which would prevent the callback to be added? As a side effect, when no_callback=False, using on_delivery by mistake should raise an error. No_callback is not a good idea because you do need a delivery report callback, otherwise you have not idea about whether the message is delivered or not.

jliunyu avatar Feb 14 '22 06:02 jliunyu