mongomq is a pub/sub implementation for golang and MongoDB.
go get -v github.com/frankffenn/mongomq
package main
import (
"context"
"log"
mq "github.com/frankffenn/mongomq"
)
func main() {
ctx := context.Background()
c, err := mq.NewChannel(ctx,
mq.Database("testdb"),
mq.Topic("testtopic"),
)
if err != nil {
log.Fatal(err)
}
go func() {
for i := 0; i < 10; i++ {
c.Publish("testtopic", "hi")
}
}()
data, err := c.Subscribe("testtopic")
if err != nil {
log.Fatal(err)
}
for {
select {
case msg := <-data:
println(msg)
}
}
}
run example
cd example/
MONGO_URI="mongodb://admin:example@127.0.0.1:27017/lotus?authsource=admin" go run *.go
View the MongoMQ Example
Just for testing. This isn't used in production yet.