Discover Packages
github.com/cybersamx/go-recipes/pubsub/kafka
command
module
Version:
v0.0.0-...-838b099
Opens a new window with list of versions in this module.
Published: Oct 3, 2023
License: MIT
Opens a new window with license information.
Imports: 12
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Kafka Pubsub using Watermill Library
An example of implementing an event-driven application using pubsub pattern with kafka as the message broker. We leverage the Watermill framework to set up our connection to kafka.
Overview
The code in this example is based on the Kafka example found in the Watermill project with the following differences:
Our example uses bitnami Kafka and Zookeeper docker images instead of Confluence docker images.
Our go program runs outside of Docker network, hence the broker URL points to localhost.
The code for sending and receiving Kafka messages are implemented as goroutines.
Setup
Run Kafka and Zookeeper.
$ docker-compose up
Run the go program.
$ go run main.go
Terminate the programs.
$ # Press CTRL-C to terminate the go program
$ # Next shutdown kafka and zookeeper
$ docker-compose down
Alternatively, you can run everything with just 2 commands.
$ make run
$ make teardown # Run this to remove the containers
Reference and Credits
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.