...

Package event

import "github.com/gonitro/nitro/app/event"
Overview
Index
Subdirectories

Overview ▾

Package event is an interface used for asynchronous messaging

type Broker

Broker is an interface used for asynchronous messaging.

type Broker interface {
    Init(...Option) error
    Options() Options
    Address() string
    Connect() error
    Disconnect() error
    Publish(event string, m *Message, opts ...PublishOption) error
    Subscribe(event string, h Handler, opts ...SubscribeOption) (Subscriber, error)
    String() string
}

type ErrorHandler

type ErrorHandler func(*Message, error)

type Handler

Handler is used to process messages via a subscription of a event.

type Handler func(*Message) error

type Message

type Message struct {
    Header map[string]string
    Body   []byte
}

type Option

type Option func(*Options)

func Addrs

func Addrs(addrs ...string) Option

Addrs sets the host addresses to be used by the event

func Codec

func Codec(c codec.Marshaler) Option

Codec sets the codec used for encoding/decoding used where a event does not support headers

func Registry

func Registry(r registry.Table) Option

func Secure

func Secure(b bool) Option

Secure communication with the event

func TLSConfig

func TLSConfig(t *tls.Config) Option

Specify TLS Config

type Options

type Options struct {
    Addrs  []string
    Secure bool
    Codec  codec.Marshaler

    TLSConfig *tls.Config
    // Registry used for clustering
    Registry registry.Table
    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context
}

type PublishOption

type PublishOption func(*PublishOptions)

func PublishContext

func PublishContext(ctx context.Context) PublishOption

PublishContext set context

type PublishOptions

type PublishOptions struct {
    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context
}

type SubscribeOption

type SubscribeOption func(*SubscribeOptions)

func HandleError

func HandleError(h ErrorHandler) SubscribeOption

ErrorHandler will catch all event errors that cant be handled in normal way, for example Codec errors

func Queue

func Queue(name string) SubscribeOption

Queue sets the name of the queue to share messages on

func SubscribeContext

func SubscribeContext(ctx context.Context) SubscribeOption

SubscribeContext set context

type SubscribeOptions

type SubscribeOptions struct {
    // Handler executed when errors occur processing messages
    ErrorHandler ErrorHandler

    // Subscribers with the same queue name
    // will create a shared subscription where each
    // receives a subset of messages.
    Queue string

    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context
}

func NewSubscribeOptions

func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions

type Subscriber

Subscriber is a convenience return type for the Subscribe method

type Subscriber interface {
    Event() string
    Options() SubscribeOptions
    Unsubscribe() error
}

Subdirectories

Name Synopsis
..
memory Package memory provides a memory event