A simple publish-subscribe messaging system built with gRPC and Go. Send messages to topics and have multiple clients receive them in real-time.
make depsThe broker must run first since it handles all message routing:
make run-brokerThis starts the broker on localhost:8080.
Open a new terminal and run:
make run-consumerThe consumer will connect to the broker and subscribe to the "kubernetes" topic.
Open another terminal and run:
make run-publisherThe publisher will send several "New release: Kubernetes 1.30 is out" messages to the "kubernetes" topic. You'll see the consumer receive these messages in real-time.
The system uses three gRPC methods defined in pubsub.proto:
- Publish: Sends a message to a topic
- Subscribe: Opens a stream to receive messages from a topic
- Unsubscribe: Stops receiving messages from a topic
The broker keeps track of which consumers are subscribed to which topics. When a publisher sends a message, the broker looks up all subscribers for that topic and forwards the message to each one.
Each consumer gets a unique ID (UUID) so the broker can track subscriptions properly.
The gRPC service is defined in pkg/protobuf/pubsub.proto with three main
operations:
Publish(PublishRequest) returns (PublishResponse)- Send a messageSubscribe(SubscribeRequest) returns (stream PayloadStream)- Receive messagesUnsubscribe(UnsubscribeRequest) returns (UnsubscribeResponse)- Stop receiving
Messages contain a topic name and payload bytes, so you can send any kind of data.