service

package
v0.0.0-...-f4396a2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoBrokerConfigured = errors.New("broker: no broker configured")
	ErrIllegalUnsubscribe = errors.New("broker: unsubscribe without prior subscription illegal")
)
View Source
var (
	ErrNoGatewayConfigured = errors.New("gateway: no gateway configured")
)

Functions

This section is empty.

Types

type Broker

type Broker interface {
	Bind(*Service)

	Subscribe(string, ChannelHandler) error
	Unsubscribe(string) error
	Publish(string, interface{}) error

	Request(string, interface{}) (*Context, error)

	Connect() error
	Disconnect() error
}

Broker is an abstraction to allow provider agnostic interactions with a event broker or message queue.

type Channel

type Channel struct {
	Name        string `json:"name"`
	Subscribers int    `json:"subscribers"`
}

Channel contains basic information about a service channel.

type ChannelHandler

type ChannelHandler func(*Context) error

ChannelHandler describes the function signature of the functions that implements the logic for the channel.

type Config

type Config struct {
	Name    string
	Version string
}

Config contains the configuration of a microservice.

type Context

type Context struct {
	Service    *Service
	Cloudevent *cloudevents.Event
}

Context is the structure of the data that is passed to a channel.

type Gateway

type Gateway interface {
	Bind(*Service)

	Route(RequestHandler)

	Listen()
}

TODO: Create abstraction such that implementation just uses enriched TCP, such that a gateway could also support MQTT or other protocols in the future.

type Request

type Request struct {
	Context interface{}

	Service *Service
}

Request is an abstract interface that provides access to to high level properties of the broker implementation.

type RequestHandler

type RequestHandler func(*Request) error

RequestHandler is the abstracted method that will be implemented by the API consumer.

type Service

type Service struct {
	Logger  *zerolog.Logger
	Broker  Broker
	Gateway Gateway
	Config  Config
	// contains filtered or unexported fields
}

Service contains the state and configuration of a microservice.

func New

func New(config Config) *Service

New returns a new service for the given configuration.

func (*Service) BrokerChannel

func (svc *Service) BrokerChannel(channel string, channelHandler ChannelHandler) *Service

func (*Service) GatewayMiddleware

func (svc *Service) GatewayMiddleware(requestHandler RequestHandler) *Service

func (*Service) Start

func (svc *Service) Start()

Start is a blocking function that starts the service.

func (*Service) UseBroker

func (svc *Service) UseBroker(b Broker) *Service

func (*Service) UseGateway

func (svc *Service) UseGateway(g Gateway) *Service

Jump to

Keyboard shortcuts

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