hub

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const AlertTopic = "hub.subscription.messageslost"

AlertTopic is used to notify when a nonblocking subscriber loose one message You can subscribe on this topic and log or send metrics.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fields

type Fields map[string]interface{}

Fields is a [key]value storage for Messages values.

func (Fields) String

func (f Fields) String() string

type Hub

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

Hub is a component that provides publish and subscribe capabilities for messages. Every message has a Name used to route them to subscribers and this can be used like RabbitMQ topics exchanges. Where every word is separated by dots `.` and you can use `*` as a wildcard.

func New

func New() *Hub

New create and return a new empty hub.

func (*Hub) Close

func (h *Hub) Close()

Close will unsubscribe all the subscriptions and close them all.

func (*Hub) NonBlockingSubscribe

func (h *Hub) NonBlockingSubscribe(cap int, topics ...string) Subscription

NonBlockingSubscribe create a nonblocking subscription to receive events for a given topic. This subscriber will loose messages if the buffer reaches the max capability.

func (*Hub) Publish

func (h *Hub) Publish(m Message)

Publish will send an event to all the subscribers matching the event name.

func (*Hub) Subscribe

func (h *Hub) Subscribe(cap int, topics ...string) Subscription

Subscribe create a blocking subscription to receive events for a given topic. The cap param is used inside the subscriber and in this case used to create a channel. cap(1) = unbuffered channel.

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(sub Subscription)

Unsubscribe remove and close the Subscription.

func (*Hub) With

func (h *Hub) With(f Fields) *Hub

With creates a child Hub with the fields added to it. When someone call Publish, this Fields will be added automatically into the message.

type Message

type Message struct {
	Name   string
	Body   []byte
	Fields Fields
}

Message represent some message/event passed into the hub It also contain some helper functions to convert the fields to primitive types.

func (*Message) Topic

func (m *Message) Topic() string

Topic return the message topic used when the message was sended.

type Subscription

type Subscription struct {
	Topics   []string
	Receiver <-chan Message
	// contains filtered or unexported fields
}

Subscription represents a topic subscription.

Jump to

Keyboard shortcuts

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