package module
v0.0.0-...-0256946 Latest Latest

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

Go to latest
Published: Apr 12, 2020 License: MIT Imports: 4 Imported by: 5


Go Pub/Sub

An in-process simple publish/subscribe library for Golang .

API Reference


I wrote this package so I can use it in my projects as a drop-in-replacement for redis pub/sub, actually this package was written for wsify v2


I'm always open for any opinion


I'm using MIT license.

Known Users




This section is empty.


This section is empty.


This section is empty.


type Broker

type Broker struct {
	// contains filtered or unexported fields

Broker The broker related meta data

func NewBroker

func NewBroker() *Broker

NewBroker Create new broker

func (*Broker) Attach

func (b *Broker) Attach() (*Subscriber, error)

Attach Create a new subscriber and register it into our main broker

func (*Broker) Broadcast

func (b *Broker) Broadcast(payload interface{}, topics ...string)

Broadcast broadcast the specified payload to all the topic(s) subscribers

func (*Broker) Detach

func (b *Broker) Detach(s *Subscriber)

Detach remove the specified subscriber from the broker

func (*Broker) GetTopics

func (b *Broker) GetTopics() []string

GetTopics Returns a slice of topics

func (*Broker) Subscribe

func (b *Broker) Subscribe(s *Subscriber, topics ...string)

Subscribe subscribes the specified subscriber "s" to the specified list of topic(s)

func (*Broker) Subscribers

func (b *Broker) Subscribers(topic string) int

Subscribers Get the subscribers count

func (*Broker) Unsubscribe

func (b *Broker) Unsubscribe(s *Subscriber, topics ...string)

Unsubscribe Unsubscribe the specified subscriber from the specified topic(s)

type Message

type Message struct {
	// contains filtered or unexported fields

Message The message metadata

func (*Message) GetCreatedAt

func (m *Message) GetCreatedAt() int64

GetCreatedAt Get the creation time of this message

func (*Message) GetPayload

func (m *Message) GetPayload() interface{}

GetPayload Get the payload of the current message

func (*Message) GetTopic

func (m *Message) GetTopic() string

GetTopic Return the topic of the current message

type Subscriber

type Subscriber struct {
	// contains filtered or unexported fields

Subscriber ...

func NewSubscriber

func NewSubscriber() (*Subscriber, error)

NewSubscriber returns a new subscriber

func (*Subscriber) AddTopic

func (s *Subscriber) AddTopic(topic string)

AddTopic Adds a new topic to the subscriber

func (*Subscriber) GetCreatedAt

func (s *Subscriber) GetCreatedAt() int64

GetCreatedAt return `time.Time` of the creation time

func (*Subscriber) GetID

func (s *Subscriber) GetID() string

GetID return the subscriber id

func (*Subscriber) GetMessages

func (s *Subscriber) GetMessages() <-chan *Message

GetMessages returns a channel of *Message to listen on

func (*Subscriber) GetTopics

func (s *Subscriber) GetTopics() []string

GetTopics return slice of subscriber topics

func (*Subscriber) RemoveTopic

func (s *Subscriber) RemoveTopic(topic string)

RemoveTopic Removes a topic from the subscriber

func (*Subscriber) Signal

func (s *Subscriber) Signal(m *Message) *Subscriber

Signal sends a message to subscriber

type Subscribers

type Subscribers map[string]*Subscriber

Subscribers ...


Path Synopsis

Jump to

Keyboard shortcuts

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