Kafka Go client: No Producer error during connection ?

Although its rare, but there are times when you actually want to see errors in your code — more importantly, at the right time !

Kafka Go Producer behaviour

You need to be mindful of this while using the Kafka Go client producer. For e.g. if you were to supply an incorrect value for the Kafka broker …

… assuming you don’t have a Kafka broker at , you would expect that the above code will respond with producer creation failed along with the specific error details. Instead, the flow carries on and ends by printing

Photo by Ken Treloar on Unsplash

This is because the error returned by is only in case message does not get enqueued to the internal queue

You should…

Hook up to the delivery producer reports channel (using ) in order to catch this error – better late than never right !

Now, the error is rightfully returned —

You can also provide your own channel to the method to receive delivery events. Only the error is handled and the other possible event i.e. is ignored under the case umbrella

Cheers!

Originally published at simplydistributed.wordpress.com on November 30, 2018.

Currently working with Kafka, Databases, Azure, Kubernetes and related open source projects | Confluent Community Catalyst (for Kafka)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store