services

package
Version: v0.0.0-...-821bb50 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseService

type BaseService struct {
	Name string

	Log zerolog.Logger

	Conn *nats.Conn

	Tasks sync.WaitGroup
	// contains filtered or unexported fields
}

BaseService is a base struct for implementing services.

func NewBaseService

func NewBaseService(name string, o Options) BaseService

NewBaseService initialize a BaseService

func (*BaseService) AddSubscription

func (s *BaseService) AddSubscription(sub *nats.Subscription)

AddSubscription save a subscription to be unsubscribed with UnsubscribeAll

func (*BaseService) GetName

func (s *BaseService) GetName() string

GetName returns the service nams

func (*BaseService) HandlerQueueSubscribe

func (s *BaseService) HandlerQueueSubscribe(handler NRPCHandler, queue string) SubscriptionDef

HandlerQueueSubscribe returnes a SubscriptionDef for a nrpc queue subscription

func (*BaseService) SafeTaskDone

func (s *BaseService) SafeTaskDone()

SafeTaskDone is a version of TaskDone that recover panics and log them.

func (*BaseService) Shutdown

func (s *BaseService) Shutdown() error

Shutdown is a default implementation that calls UnsubscribeAll()

func (*BaseService) SubscribeAll

func (s *BaseService) SubscribeAll(subdefs ...SubscriptionDef) error

SubscribeAll do multiple subscriptions at once and returns immediately on the first failing subscription.

func (*BaseService) TaskAdd

func (s *BaseService) TaskAdd()

TaskAdd signal that a task just started. It will block service shutdown until TaskDone is called.

func (*BaseService) TaskDone

func (s *BaseService) TaskDone()

TaskDone signal the end of a task, allowing the service to shutdown if no other task is running.

func (*BaseService) UnsubscribeAll

func (s *BaseService) UnsubscribeAll() error

UnsubscribeAll unsubscribe and forget all the subscriptions

type Manager

type Manager struct {
	Log zerolog.Logger
	// contains filtered or unexported fields
}

Manager ...

func NewManager

func NewManager(logger zerolog.Logger) *Manager

NewManager initialize a Manager

func (*Manager) Add

func (s *Manager) Add(service Service)

Add adds a service

func (*Manager) Shutdown

func (s *Manager) Shutdown() error

Shutdown stops running services

func (*Manager) Startup

func (s *Manager) Startup() error

Startup starts all the services

type NRPCHandler

type NRPCHandler interface {
	Subject() string
	Handler(*nats.Msg)
}

NRPCHandler ...

type Options

type Options struct {
	Conn   *nats.Conn
	Logger zerolog.Logger
}

Options is the common options of xbus services

type Service

type Service interface {
	// GetName returns the service name
	GetName() string

	// Startup will do what is necessary for the service to be up and running
	Startup() error

	// Shutdown should stop the service and release any resource allocated by
	// Startup
	Shutdown() error
}

Service is the common interface of all the services

type SubscriptionDef

type SubscriptionDef struct {
	Subject string
	Queue   string
	Handler nats.MsgHandler
}

SubscriptionDef is a definition of a nats subscription

func QueueSubscribe

func QueueSubscribe(subject, queue string, handler nats.MsgHandler) SubscriptionDef

QueueSubscribe returns a SubscriptionDef for queue subscription

func Subscribe

func Subscribe(subject string, handler nats.MsgHandler) SubscriptionDef

Subscribe returns a SubscriptionDef for simple subscription

Directories

Path Synopsis
Package core provides the 'core' service, which must be started once and only once in every server process
Package core provides the 'core' service, which must be started once and only once in every server process
Package sentrycapture provides the 'core' service, which must be started once and only once in every server process
Package sentrycapture provides the 'core' service, which must be started once and only once in every server process

Jump to

Keyboard shortcuts

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