Skip to content

Latest commit

 

History

History
66 lines (46 loc) · 1.24 KB

File metadata and controls

66 lines (46 loc) · 1.24 KB

PubSub Patern in Go

Implementation of Publisher and Suscribers patter in Go

How to run

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 up

And you're ready to go.

Usage

Connect

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

First message have to be a name otherwise it'll close the connection: e.g.:

{ "name": "Jhon" }

Subscribe

Then you can subscribe to a topic with the SUB command to receive messages from a topic:

{ "Command": "SUB", "Topic": "news" }

Publish

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"
}

Features

  • Subscribe
  • Unsubscribe
  • Unsubscribe all
  • Send msg via Broker
  • Handle multiples clients
  • Include name in messages
  • Use channels
  • Dockerize
  • Logs
  • DB connection
  • Auth