Documentation ¶
Index ¶
- Variables
- func NewAsyncCommandHandler(svc control.Service, payloadType message.AsyncCommand, ...) control.MessageHandler
- func NewService(ctx context.Context, connection ctrl.Connection) *service
- func WithCachingService(ctx context.Context) control.ServiceWrapper
- type AsyncCommandMessage
- type MessageRouter
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
func (ac *AsyncCommandMessage) Headers() control.MessageHeader
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)