It's often useful not to wait for a Kafka producer to complete before moving on to the next task. In cases like this, you can use an asynchronous 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 ofthe Using Kafka with Sarama recipe.
How to do it...
These steps cover writing and running your application:
- From your Terminal or console application,createa new directory called~/projects/go-programming-cookbook/chapter12/asynckafkaand navigate to this directory.
- Run this command:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook...