https://github.com/picosh/pubsub
A generic pubsub implementation for Go
https://github.com/picosh/pubsub
Last synced: 2 months ago
JSON representation
A generic pubsub implementation for Go
- Host: GitHub
- URL: https://github.com/picosh/pubsub
- Owner: picosh
- License: mit
- Created: 2024-08-30T04:14:32.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-11-12T16:24:45.000Z (6 months ago)
- Last Synced: 2024-11-12T17:28:44.998Z (6 months ago)
- Language: Go
- Homepage: https://pipe.pico.sh
- Size: 98.6 KB
- Stars: 26
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-repositories - picosh/pubsub - A generic pubsub implementation for Go (Go)
README
# pubsub
A generic pubsub implementation for Go.
```go
package mainimport (
"bytes"
"context"
"fmt"
"log/slog""github.com/picosh/pubsub"
)func main() {
ctx := context.TODO()
logger := slog.Default()
broker := pubsub.NewMulticast(logger)chann := []*pubsub.Channel{
pubsub.NewChannel("my-topic"),
}go func() {
writer := bytes.NewBufferString("my data")
_ = broker.Pub(ctx, "pubID", writer, chann, false)
}()reader := bytes.NewBufferString("")
_ = broker.Sub(ctx, "subID", reader, chann, false)// result
fmt.Println("data from pub:", reader)
}
```## pubsub over ssh
The simplest pubsub system for everyday automation needs.
Using `wish` we can integrate our pubsub system into an SSH app.
[](https://asciinema.org/a/674287)
```bash
# term 1
mkdir ./ssh_data
cat ~/.ssh/id_ed25519 ./ssh_data/authorized_keys
go run ./cmd/example# term 2
ssh -p 2222 localhost sub xyz# term 3
echo "hello world" | ssh -p 2222 localhost pub xyz
```