Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hlts2/gopubsub
Simple lock-free topick based publish/subscribe library written in golang
https://github.com/hlts2/gopubsub
golang golang-library goroutine-safe goroutines hlts2 library lock-free pubsub pubsub-instance pubsub-messages topic
Last synced: 24 days ago
JSON representation
Simple lock-free topick based publish/subscribe library written in golang
- Host: GitHub
- URL: https://github.com/hlts2/gopubsub
- Owner: hlts2
- License: mit
- Created: 2018-07-05T08:06:03.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-27T16:14:58.000Z (over 6 years ago)
- Last Synced: 2024-06-20T03:29:04.624Z (5 months ago)
- Topics: golang, golang-library, goroutine-safe, goroutines, hlts2, library, lock-free, pubsub, pubsub-instance, pubsub-messages, topic
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gpubsub
gpubsub is a [topic-based](http://en.wikipedia.org/wiki/Publish–subscribe_pattern#Message_filtering) [publish/subscribe](http://en.wikipedia.org/wiki/Publish/subscribe) library written in golang.
## Requirement
Go (>= 1.8)
## Installation
```shell
go get github.com/hlts2/gopubsub
```## Example
To subscribe:
```go
ps := gopubsub.NewPubSub()subscriber := ps.Subscribe("t1")
```To add subscribe:
```go
subscriber := ps.Subscribe("t1")// Adds subscriptions
ps.AddSubsrcibe("t2", subscriber)
```To publish:
```go
// 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:
```go
ps.UnSubscribe("t1")
```To fetch published message
```go
message := <-subscriber.Read()
```## Author
[hlts2](https://github.com/hlts2)## LICENSE
gopubsub released under MIT license, refer [LICENSE](https://github.com/hlts2/gopubsub/blob/master/LICENSE) file.