sarama
Sarama is a Go library for Apache Kafka.
Sarama is a Go library maintained by IBM that lets Go applications send messages to, read from, and administer Apache Kafka, the high-speed messaging system used to stream data between services at scale.
Apache Kafka is a messaging system designed to move large streams of data between applications reliably and at high speed. Rather than having systems communicate directly with each other, producers write messages to Kafka and consumers read from it on their own schedule. This decoupling allows many services to process data independently and makes it easier to scale each part of a system without affecting the others.
Sarama is a Go programming language library that lets Go applications connect to Apache Kafka. Using Sarama, a Go program can send messages to Kafka (acting as a producer), read messages from it (acting as a consumer), or administer a Kafka cluster, without having to implement the underlying Kafka wire protocol from scratch.
The library is maintained by IBM under an MIT open-source license. It follows a compatibility policy that supports the two most recent stable releases of both Kafka and Go at any time, with a two-month grace period for older versions. Older Kafka releases outside that window may still work even if they are not officially supported.
The README is brief and directs readers to external resources for detail. Full API documentation and examples are hosted at pkg.go.dev. A FAQ covers common issues on the project wiki. The library includes a mocks subpackage for writing automated tests and a tools directory with command-line utilities for diagnosing Kafka connections.
Version numbering follows standard Go module conventions, so breaking changes are signaled through major version bumps and the changelog tracks each release.
Where it fits
- Send messages from a Go service to a Kafka topic so other services can consume them asynchronously.
- Build a Go consumer group that reads events from Kafka and processes them in real time.
- Write automated tests for Kafka-connected Go code using Sarama's built-in mock package without a real Kafka cluster.
- Administer a Kafka cluster, create topics, check offsets, manage partitions, directly from a Go application.