/goq

Golang interprocess, in-memory pub-sub message queue.

Primary LanguageGoMIT LicenseMIT

goq

Go Reference

Golang interprocess, in-memory pub-sub message queue.

Install

goq requires go1.18 or later.

go get -u github.com/piotrpersona/goq

Examples

Checkout examples/ directory. Run

go run examples/pubsub/main.go

Usage

Create topic:

q := goq.New[int, string]()
q.CreateTopic("topic")

Create callback:

type callback struct {}

func (c callback) Handle(msg goq.Message[int, string]) {
    fmt.Printf("key: %d value: %s", msg.Key, msg.Value)
}

Subscribe to a topic:

started, err := q.Subscribe(topic, "example-subscriber", &callback{})
<-started

Publish to a topic:

q.Publish("topic", goq.Message[int, string]{1, "Hello world!"})

Stop queue:

<-q.Stop() // <-chan struct{}

NOTE

Publish and Unsubscribe works asynchronously. Subscriber and Stop should be awaited.