gpubsub is a topic-based publish/subscribe library written in golang.
Go (>= 1.8)
go get github.com/hlts2/gopubsubTo subscribe:
ps := gopubsub.NewPubSub()
subscriber := ps.Subscribe("t1")To add subscribe:
subscriber := ps.Subscribe("t1")
// Adds subscriptions
ps.AddSubsrcibe("t2", subscriber)To publish:
// publish message to topic asyncronously
ps.Publish("t1", "Hello World!!")
// Because the message type is `interface{}`, you can publish anything
ps.Publish("t1", func() {
fmt.Println("Hello World!!")
})To Cancel specific subscription:
ps.UnSubscribe("t1")To fetch published message
message := <-subscriber.Read()gopubsub released under MIT license, refer LICENSE file.