usrv

package module
v0.0.0-...-0173b98 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2015 License: MIT Imports: 4 Imported by: 0

README

usrv

A microservice framework for go

Documentation

Index

Constants

View Source
const (
	PropertyHasError = "error"
)

Common message property names

Variables

View Source
var (
	ErrEndpointAlreadyBound = errors.New("Endpoint already bound")
	ErrNoEndpointsBound     = errors.New("No endpoints bound")
	ErrServiceUnavailable   = errors.New("Service unavailable")
	ErrTimeout              = errors.New("Request timeout")
)
View Source
var NullLogger = nullLogger{}

The NullLogger discards any log message

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(service string, transport Transport) *Client

func (*Client) NewMessage

func (c *Client) NewMessage(from string, toEndpoint string) Message

func (*Client) Send

func (c *Client) Send(msg Message, timeout time.Duration) <-chan Message

type Handler

type Handler func(req, res Message)

Endpoint handlers should match this signature.

type Logger

type Logger interface {
	Trace(msg string, args ...interface{})
	Debug(msg string, args ...interface{})
	Info(msg string, args ...interface{})
	Warn(msg string, args ...interface{}) error
	Error(msg string, args ...interface{}) error
	Fatal(msg string, args ...interface{})
}

The Logger interface must be implemented by any logger that can be plugged into usrv.

This interface has been copied from logxi (https://github.com/mgutz/logxi)

type Message

type Message interface {
	From() string
	To() string
	Property() Property
	CorrelationId() string

	Content() ([]byte, error)
	SetContent([]byte, error)
}

The message interface is implemented by all messages that can be passed through a transport.

type Property

type Property map[string]string

func (Property) Del

func (p Property) Del(key string)

Delete a propery key.

func (Property) Get

func (p Property) Get(key string) string

Get a key from the property set.

func (Property) Set

func (p Property) Set(key string, value string)

Set a property key.

type Server

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

func NewServer

func NewServer(service string, transport Transport) *Server

func (*Server) Close

func (srv *Server) Close() error

Shut down the server.

func (*Server) Handle

func (srv *Server) Handle(endpoint string, handler Handler) error

Bind endpoint.

func (*Server) Listen

func (srv *Server) Listen() error

Listen for incoming messages and dispatch them to the registered endpoints.

type Transport

type Transport interface {

	// Attach a logger to the transport.
	SetLogger(logger Logger)

	// Configure the transport.
	Config(params map[string]string) error

	// Close the transport.
	Close() error

	// Bind service endpoint. Returns a channel that emits incoming Messages to that endpoint
	Bind(service string, endpoint string) (<-chan Message, error)

	// Send a message.
	Send(message Message, timeout time.Duration, expectReply bool) <-chan Message

	// Create a message to be delivered to a target endpoint
	MessageTo(from string, toService string, toEndpoint string) Message

	// Create a message that serves as a reply to an incoming message
	ReplyTo(message Message) Message
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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