Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nicwaller/udp_pubsub
A publish/subscribe message bus using UDP broadcast packets
https://github.com/nicwaller/udp_pubsub
Last synced: about 6 hours ago
JSON representation
A publish/subscribe message bus using UDP broadcast packets
- Host: GitHub
- URL: https://github.com/nicwaller/udp_pubsub
- Owner: nicwaller
- Created: 2023-10-14T18:52:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-14T19:09:04.000Z (over 1 year ago)
- Last Synced: 2024-06-21T03:29:10.775Z (8 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# udp_pubsub
A publish/subscribe message bus using UDP broadcast packets.
## Why
The [publish-subscribe channel](https://www.enterpriseintegrationpatterns.com/patterns/messaging/PublishSubscribeChannel.html) is a useful design pattern, and there are great tools like [Redis Pub/Sub](https://redis.io/docs/interact/pubsub/) to support it, but sometimes I just want something **very** lightweight.
The usual ways of designing inter-process communication (IPC) don't allow the fan-out afforded by publish-subscribe channels. Unix domain sockets and unix pipes are both designed to work with a single listener.
## How
UDP broadcast is actually perfect for this. The publisher sends broadcast packets on a known port, and any process on any host of the local network broadcast segment can become a subscriber just by listening for packets on that same port.
The thing that makes this work with multiple processes on the same host is use of [SO_REUSEPORT](https://lwn.net/Articles/542629/).
## Usage
```shell
(pushd publisher && go build && ./publisher) &
(pushd subscriber && go build && ./subscriber)
```## Limitations
Broadcasting to `255.255.255.255` _really does_ send to every machine on the local broadcast segment of the network. This behaviour may be desirable (or not) depending on your needs and your network architecture.