https://github.com/manav2401/go-pubsub
A simple pub sub mechanism in Go
https://github.com/manav2401/go-pubsub
Last synced: 2 months ago
JSON representation
A simple pub sub mechanism in Go
- Host: GitHub
- URL: https://github.com/manav2401/go-pubsub
- Owner: manav2401
- License: mit
- Created: 2023-07-22T16:10:18.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-22T17:05:13.000Z (almost 2 years ago)
- Last Synced: 2025-01-29T12:11:17.018Z (4 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go pubsub
A simple pub sub mechanism in GoIt uses a simple broker based mechanism to manage different topics of communication.
### Usage
Here's a sample code to use this go-pubsub.
```go
// Initialise a new broker
broker := pubsub.NewBroker()// Create a new topic (and also get auto-subscribed)
topic := broker.NewTopic("topic-name", 10)// Publish new messages to topic
topic.Publish([]("Hello World!"))// Get a new topic and subscribe to it. Returns the id and channel
// to listen to published messages.
t := broker.Topic("topic-name")
id, ch, err := t.Subscribe()// Unsubscribe using subscriber id
err := topic.Unsubscribe(id)// Close the broker
broker.End()
```