This is a sample project to use sarama, sarama is golang client library for Apache kafka. This repositry contains simple producer and consumer. To use this you need to prepare kafka (or you can run it by docker image).
To get sarama,
$ go get github.com/Shopify/sarama
To build producer & consumer, run below. Binary is generated in each directory,
$ make build
Ensure kafka is running on where you expect.
To execute consumer, run below. Consumer tries to fetch topic until received os.Interrupt
signal.
$ ./consumer/consumer
To execute async-producer, run below. Producer tries to publish messages until received os.Interrupt
signal.
$ ./async-producer/async-producer
You can run kafka on docker. And you can also run producer & consumer on docker.
To build docker image of kafka,
$ make docker-build
To run kafka container,
$ ./docker-run.sh
To execute consumer,
$ docker exec -it kafka /work/consumer/consumer
To execute async-producer,
$ docker exec -it kafka /work/async-producer/async-producer
To execute http-log-producer,
$ docker exec -it kafka /work/http-log-producer/http-log-producer
And access it (e.g., docker is on boot2docker),
$ curl $(boot2docker ip):8080