service

package
v0.0.0-...-330c09c Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoggerErrorHandler ctrl.ErrorHandlerFunc = func(ctx context.Context, err error) {
	logging.FromContext(ctx).Debugf("Error from the connection: %s", err)
}

LoggerErrorHandler is a default noop error handler that logs the error.

View Source
var NoopMessageHandler ctrl.MessageHandlerFunc = func(ctx context.Context, message ctrl.ServiceMessage) {
	logging.FromContext(ctx).Warnf("Discarding control message '%s'", message.Headers().UUID())
	message.Ack()
}

NoopMessageHandler is a default noop message handler that logs the message and acks it.

Functions

func NewAsyncCommandHandler

func NewAsyncCommandHandler(svc control.Service, payloadType message.AsyncCommand, resultOpCode control.OpCode, handler func(context.Context, AsyncCommandMessage)) control.MessageHandler

NewAsyncCommandHandler returns a control.MessageHandler that wraps the provided handler, but passing an AsyncCommandMessage. This handler automatically parses the message payload using the provided type, and using the AsyncCommandMessage it notifies the result of the command to the sender.

func NewService

func NewService(ctx context.Context, connection ctrl.Connection) *service

func WithCachingService

func WithCachingService(ctx context.Context) control.ServiceWrapper

WithCachingService will cache last message sent for each opcode and, in case you try to send a message again with the same opcode and payload, the message won't be sent again.

Types

type AsyncCommandMessage

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

AsyncCommandMessage is a command message that notifies asynchronously the completion of the execution. Look at NewAsyncCommandHandler for more details.

func (*AsyncCommandMessage) Headers

Headers returns the message headers

func (*AsyncCommandMessage) NotifyFailed

func (ac *AsyncCommandMessage) NotifyFailed(err error)

NotifyFailed will notify a failure in the handling of the control message If err == nil, this acts the same as NotifySuccess

func (*AsyncCommandMessage) NotifySuccess

func (ac *AsyncCommandMessage) NotifySuccess()

NotifySuccess will notify the success of the handling of the control message

func (*AsyncCommandMessage) ParsedCommand

func (ac *AsyncCommandMessage) ParsedCommand() message.AsyncCommand

ParsedCommand returns the command parsed in the specified type

type MessageRouter

type MessageRouter map[control.OpCode]control.MessageHandler

func (MessageRouter) HandleServiceMessage

func (c MessageRouter) HandleServiceMessage(ctx context.Context, message control.ServiceMessage)

Jump to

Keyboard shortcuts

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