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

… assuming you don’t have a Kafka broker at foo:9092, 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 done

Photo by Ken Treloar on Unsplash

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

You should…

Now, the error is rightfully returned — producer error foo:9092/bootstrap: Failed to resolve 'foo:9092': nodename nor servname provided, or not known (after 1543569582778ms in state INIT)

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

Cheers!

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

--

--

Principal Developer Advocate at AWS | I ❤️ Databases, Go, Kubernetes

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
Abhishek Gupta

Principal Developer Advocate at AWS | I ❤️ Databases, Go, Kubernetes