gopubsub

package module
v0.0.0-...-ffb3725 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 3 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PubSub

type PubSub struct {
	// contains filtered or unexported fields
}

PubSub is pubsub messasing object

func NewPubSub

func NewPubSub() *PubSub

NewPubSub returns PubSub object

func (*PubSub) AddSubsrcibe

func (p *PubSub) AddSubsrcibe(topic string, target Subscriber) Subscriber

AddSubsrcibe adds subscribes into a topic

func (*PubSub) Publish

func (p *PubSub) Publish(topic string, message interface{})

Publish sends a message to subscribers subscribing to topic

func (*PubSub) Subscribe

func (p *PubSub) Subscribe(topic string) Subscriber

Subscribe subscribes to a topic

func (*PubSub) UnSubscribe

func (p *PubSub) UnSubscribe(topic string, target Subscriber)

UnSubscribe unsubscribes topic

type Subscriber

type Subscriber interface {
	Read() <-chan interface{}
}

Subscriber is interface that wraps the Read methods

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL