rmb

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultAddress default redis address when no address is passed
	DefaultAddress = "tcp://127.0.0.1:6379"
)

Variables

View Source
var (
	// ErrFunctionNotFound is an err returned if the handler function is not found
	ErrFunctionNotFound = fmt.Errorf("function not found")
)

Functions

func GetTwinID

func GetTwinID(ctx context.Context) uint32

GetTwinID returns the twin id from context.

func LoggerMiddleware

func LoggerMiddleware(ctx context.Context, payload []byte) (context.Context, error)

LoggerMiddleware simple logger middleware.

Types

type Client

type Client interface {
	Call(ctx context.Context, twin uint32, fn string, data interface{}, result interface{}) error
}

Client is an rmb abstract client interface.

func Default

func Default() (Client, error)

Default return instance of to default (local) rmb shortcut for NewClient(DefaultAddress)

func NewClient

func NewClient(address string, poolSize ...uint32) (Client, error)

NewClient creates a new rmb client. the given address should be to the local redis. If not provided, default redis address is used poolSize is optional parameter to define redis pool size (Default: 20)

type Handler

type Handler func(ctx context.Context, payload []byte) (interface{}, error)

Handler is a handler function type

type Message

type Message struct {
	Version    int      `json:"ver"`
	UID        string   `json:"uid"`
	Command    string   `json:"cmd"`
	Expiration int      `json:"exp"`
	Retry      int      `json:"try"`
	Data       string   `json:"dat"`
	TwinSrc    uint32   `json:"src"`
	TwinDest   []uint32 `json:"dst"`
	Retqueue   string   `json:"ret"`
	Schema     string   `json:"shm"`
	Epoch      int64    `json:"now"`
	Err        string   `json:"err"`
	// Proxy flag is only used to keep the value sent by
	// msgbusd. because it need to be send back as is to
	// the daemon. While it's not used in the client side
	// it need to stay
	Proxy bool `json:"pxy"`
}

Message is an struct used to communicate over the messagebus

func GetMessage

func GetMessage(ctx context.Context) Message

GetMessage gets a message from the context, panics if it's not there

func (*Message) GetPayload

func (m *Message) GetPayload() ([]byte, error)

GetPayload returns the payload for a message's data

type MessageBus

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

MessageBus is a struct that contains everything required to run the message bus

func New

func New(address string) (*MessageBus, error)

New creates a new message bus

func (*MessageBus) Handlers

func (m *MessageBus) Handlers() []string

Handlers return full name of all registered handlers

func (*MessageBus) Run

func (m *MessageBus) Run(ctx context.Context) error

Run runs listeners to the configured handlers and will trigger the handlers in the case an event comes in

func (*MessageBus) Subroute

func (m *MessageBus) Subroute(prefix string) Router

func (*MessageBus) Use

func (m *MessageBus) Use(mw Middleware)

func (*MessageBus) WithHandler

func (m *MessageBus) WithHandler(topic string, handler Handler)

WithHandler adds a topic handler to the messagebus

type Middleware

type Middleware func(ctx context.Context, payload []byte) (context.Context, error)

Middleware is middleware function type

type Router

type Router interface {
	WithHandler(route string, handler Handler)
	Subroute(route string) Router
	Use(Middleware)
}

Router is the router interface

Jump to

Keyboard shortcuts

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