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
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
This is because the error returned by
Produce is only in case message does not get enqueued to the internal
Hook up to the delivery producer reports channel (using
Producer.Events()) in order to catch this error – better late than never right !
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
Originally published at simplydistributed.wordpress.com on November 30, 2018.