pubsub

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PubWithContext

func PubWithContext(ctx context.Context, pub Pub) context.Context

PubWithContext returns a copy of parent in which the `Pub` is stored

func SubWithContext

func SubWithContext(ctx context.Context, sub Sub) context.Context

SubWithContext returns a copy of parent in which the `Sub` is stored

func WithContext

func WithContext(ctx context.Context, ps PubSub) context.Context

WithContext returns a copy of parent in which `PubSub`, `Pub`, and `Sub` are stored

Types

type MsgHandler

type MsgHandler func(context.Context, []byte)

type Pub

type Pub interface {
	// Publish publishes data to the channel ch
	Publish(ctx context.Context, ch string, data []byte) error
}

Pub is the publish interface

func PubFromContext

func PubFromContext(ctx contextutil.ValueContext) Pub

PubFromContext returns a `Pub` instance associated with `ctx`, or the local `Pub` if no instance could be found.

type PubSub

type PubSub interface {
	Pub
	Sub

	// Start does the initialisation work to bootstrap a PubSub adapter.
	// For example, this function may open a connection, start an event loop, etc.
	Start(ctx context.Context) error
	// Drain signals to the pubsub client/server that inbound messages should
	// no longer be accepted, but outbound messages can still be delivered.
	Drain()
	// Close closes the client/server for both inbound/outbound messages
	Close() error
}

func FromContext

func FromContext(ctx contextutil.ValueContext) PubSub

FromContext returns a `PubSub` instance associated with `ctx`, or the local `Sub` if no instance could be found.

func Log

func Log(p PubSub) PubSub

Log wraps `p` with trace logs

func NopPubSub

func NopPubSub() PubSub

NopPubSub returns a PubSub adapter which discards all pubs

func Recover

func Recover(p PubSub) PubSub

Recover wraps `p` with a middleware that recovers from panics in Subscribe

func Stats

func Stats(p PubSub) PubSub

Stats wraps `p` with stats

func Trace

func Trace(p PubSub) PubSub

Trace wraps `p` with a trace middleware

type Sub

type Sub interface {
	// Subscribe subscribes the message handler h to the channel ch.
	// All subscriptions with the same q will form a queue group.
	// Each message will be delivered to only one subscriber per queue group.
	Subscribe(q, ch string, h MsgHandler) error
}

Sub is the subscribe interface

func SubFromContext

func SubFromContext(ctx contextutil.ValueContext) Sub

SubFromContext returns a `Sub` instance associated with `ctx`, or the local `Sub` if no instance could be found.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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