Skip to content
/ gopubsub Public

Simple lock-free topick based publish/subscribe library written in golang

License

Notifications You must be signed in to change notification settings

hlts2/gopubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.