Implementation of Publisher and Suscribers patter in Go
You can, maybe, run mongodb on your own, an then do something like go run main.go.
But, I highly recommend you to just use docker compose as:
docker compose upAnd you're ready to go.
You'll need a websocket client, either build one or use one like wscat as I do.
Connect to ws://localhost:9876/ws
All comunnication must be in json format
First message have to be a name otherwise it'll close the connection:
e.g.:
{ "name": "Jhon" }Then you can subscribe to a topic with the SUB command to receive messages from a topic:
{ "Command": "SUB", "Topic": "news" }Or, send message to a topic with PUB command. You can send a message without being subscribed to it. Feature, not a bug.
{
"Command": "PUB",
"Topic": "Sports",
"Message": "Germany 7-1 Brazil"
}- Subscribe
- Unsubscribe
- Unsubscribe all
- Send msg via Broker
- Handle multiples clients
- Include name in messages
- Use channels
- Dockerize
- Logs
- DB connection
- Auth