https://github.com/dewadg/haro
A Go pubsub helper
https://github.com/dewadg/haro
golang pubsub
Last synced: 5 months ago
JSON representation
A Go pubsub helper
- Host: GitHub
- URL: https://github.com/dewadg/haro
- Owner: dewadg
- License: mit
- Created: 2020-06-17T04:51:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-17T10:55:04.000Z (about 4 years ago)
- Last Synced: 2024-06-20T17:39:49.618Z (about 2 years ago)
- Topics: golang, pubsub
- Language: Go
- Homepage:
- Size: 53.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Haro
Topic-based pubsub library.
[](https://goreportcard.com/report/github.com/dewadg/haro)
[](https://github.com/dewadg/haro/actions)
[](https://coveralls.io/github/dewadg/haro?branch=master)
[](https://pkg.go.dev/github.com/dewadg/haro?tab=doc)
## Usage
Install with:
```
go get github.com/dewadg/haro
```
### Declaring topic
```go
intTopic := haro.DeclareTopic[int]()
stringTopic := haro.DeclareTopic[string]()
```
### Registering subscribers
```go
intTopic.Subscribe(func(ctx context.Context, p int) error {
return nil
})
stringTopic.Subscribe(func(ctx context.Context, p string) error {
return nil
})
```
### Publishing
```go
var err error
err = intTopic.Publish(context.Background(), 5)
err = stringTopic.Publish(context.Background(), "test")
```
## Limitations
- It's not a distributed pubsub mechanism, it means pubsub across different instances won't work (eg: across docker container replication)
- No recovery since it doesn't utilize any external storage, it's purely using Channel to store the published messages