sotirispl / kafka-example

A simple example how to produce and consume Kafka messages using Golang.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setup

Start kafka container at localhost:9092

docker-compose up -d kafka

If this address is already in use, edit the host and port into docker-compose.yml file. Also, edit consumer and producer vars for broker list.

Producer

go run cmd/producer/main.go

Available flags:

  • topic (default: the_topic)
  • msg (default: an important message)
  • key (default: a_key)

Output: Send a message in topic the_topic - partition 0 - offset 1

Consumer

go run cmd/producer/main.go

Available flags:

  • topic (default: the_topic)

Output: Got key "a_key" with message "an important message"

To stop consumer's execution send an interruption singal Ctrl+C

About

A simple example how to produce and consume Kafka messages using Golang.


Languages

Language:Go 100.0%