https://github.com/mehdieidi/pubsub
Distributed Many-to-Many pub sub service.
https://github.com/mehdieidi/pubsub
go golang message-broker publisher-subscriber pubsub
Last synced: 5 months ago
JSON representation
Distributed Many-to-Many pub sub service.
- Host: GitHub
- URL: https://github.com/mehdieidi/pubsub
- Owner: mehdieidi
- License: gpl-3.0
- Created: 2022-03-31T19:53:15.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-08T14:19:03.000Z (about 4 years ago)
- Last Synced: 2025-03-22T07:53:27.724Z (over 1 year ago)
- Topics: go, golang, message-broker, publisher-subscriber, pubsub
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pubsub
Distributed Many-to-Many pub sub service.
The broker is a server which handles the publish and subscribe functionalities.
To start the broker server:
```
$ cd pubsub/cmd
go run .
```
## Subscriber clients
Subscriber clients must have an HTTP address so the broker server can send messages back to this address.
Subscriber clients need to introduce themselves to the broker server and subscribe for topics.
Create new subscriber client and marshall. Example:
```
s := subscriber.New("http://localhost:8081", []string{"football", "volleyball", "handball"}, true)
j, _ := json.Marshal(s)
```
Clients should start listening before introducing themselves to the server. (In a separate goroutine).
The s.Listen() will populate the msg variable when received data.
```
var msg message.Message
go s.Listen(&msg)
```
Register with the server and subscribe for the defined topics:
```
http.Post("http://localhost:8080/subscribe", "application/json", bytes.NewBuffer(j))
```
The s.Listen method will handle the incoming messages from the broker server.
## Publishing messages
For publishing messages, publishers only need to send a POST request with the defined json structure to the broker server:
```
// send post request with this json structure to the /publish endpoint:
{
"topic": "handball",
"body": "a sample message"
}
```