Publishing messages with Kafka

The Sarama library offers two implementations for publishing messagesthe sarama.SyncProducer and the sarama.AsyncProducer.

The AsyncProducer offers an asynchronous interface that uses Go channels both for publishing messages and for checking the success of these operations. It allows high-throughput of messages, but is a bit bulky to use if all you want to do is to emit a single message. For this reason, the SyncProducer offers a simpler interface that takes a message for producing and blocks until it receives confirmation from the broker that the message has been successfully published to the event log.

You can instantiate a new Producer using the sarama.NewSyncProducerFromClient and sarama.NewAsyncProducerFromClient ...

Get Cloud Native programming with Golang now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.