Using async producers with Kafka
It's often useful to not wait for a Kafka producer to complete before moving on to the next task. In cases like this, you can use an async producer. These producers take Sarama messages on a channel and have methods to return a success/error channel that can be checked separately.
In this recipe, we'll create a go routine that will handle success and failure messages while we allow a handler to queue messages to send regardless of the result.
Getting ready
Refer to the Getting ready section of the Using Kafka with Sarama recipe.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create the
chapter11/asyncsarama
directory and navigate to it. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter11/asyncsarama or use this as an exercise to write some of your own.
- Ensure that Kafka is up and running on
localhost:9092
. - Copy the consumer directory from the previous recipe.
- Create a directory...