Skip to content

Latest commit

 

History

History
63 lines (41 loc) · 1.04 KB

README.md

File metadata and controls

63 lines (41 loc) · 1.04 KB

gpubsub

gpubsub is a topic-based publish/subscribe library written in golang.

Requirement

Go (>= 1.8)

Installation

go get github.com/hlts2/gopubsub

Example

To 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()

Author

hlts2

LICENSE

gopubsub released under MIT license, refer LICENSE file.