Documentation
¶
Index ¶
- Constants
- type Async
- type Bus
- func (bus *Bus) Handle(cmd Command) (any, error)
- func (bus *Bus) HandleAsync(cmd Command) (*Async, error)
- func (bus *Bus) HandleClosure(cmd ClosureCommand) *Async
- func (bus *Bus) Initialize(hdls ...Handler) error
- func (bus *Bus) RemoveScheduled(keys ...uuid.UUID)
- func (bus *Bus) Schedule(cmd Command, sch *schedule.Schedule) (*uuid.UUID, error)
- func (bus *Bus) SetErrorHandlers(hdls ...ErrorHandler)
- func (bus *Bus) SetInwardMiddlewares(mdls ...InwardMiddleware)
- func (bus *Bus) SetOutwardMiddlewares(mdls ...OutwardMiddleware)
- func (bus *Bus) SetQueueBuffer(queueBuffer int)
- func (bus *Bus) SetWorkerPoolSize(workerPoolSize int)
- func (bus *Bus) Shutdown()
- type BusError
- type ClosureCommand
- type Command
- type ErrorHandler
- type Handler
- type Identifier
- type InwardMiddleware
- type OutwardMiddleware
Constants ¶
const ( // InvalidCommandError will be returned when attempting to handle an invalid command. InvalidCommandError = BusError("command: invalid command") // BusNotInitializedError will be returned when attempting to handle a command before the bus is initialized. BusNotInitializedError = BusError("command: the bus is not initialized") // BusIsShuttingDownError will be returned when attempting to handle a command while the bus is shutting down. BusIsShuttingDownError = BusError("command: the bus is shutting down") // OneHandlerPerCommandError will be returned when attempting to initialize the bus with more than one handler listening to the same command. OneHandlerPerCommandError = BusError("command: there can only be one handler per command") // HandlerNotFoundError will be returned when no handler is found to the provided command. HandlerNotFoundError = BusError("command: no handler found for the command provided") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Async ¶ added in v1.3.0
type Async struct {
// contains filtered or unexported fields
}
Async is the struct returned from async commands.
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is the only struct exported and required for the command bus usage. The Bus should be instantiated using the NewBus function.
func NewBus ¶
func NewBus() *Bus
NewBus instantiates the Bus struct. The Initialization of the Bus is performed separately (Initialize function) for dependency injection purposes.
func (*Bus) HandleAsync ¶
HandleAsync processes the command asynchronously using workers through their respective handler. It also returns an *Async struct which allows clients to optionally ```Await``` for the command to be processed.
func (*Bus) HandleClosure ¶ added in v1.4.0
func (bus *Bus) HandleClosure(cmd ClosureCommand) *Async
HandleClosure processes a closure command asynchronously using workers. It also returns an *Async struct which allows clients to optionally ```Await``` for the command to be processed.
func (*Bus) Initialize ¶
Initialize the command bus by providing the list of handlers. There can only be one handler per command.
func (*Bus) RemoveScheduled ¶ added in v1.2.0
RemoveScheduled removes previously scheduled commands.
func (*Bus) Schedule ¶ added in v1.2.0
Schedule allows commands to be scheduled to be executed asynchronously. Check https://github.com/io-da/schedule for ```*Schedule``` usage.
func (*Bus) SetErrorHandlers ¶ added in v1.3.0
func (bus *Bus) SetErrorHandlers(hdls ...ErrorHandler)
SetErrorHandlers may optionally be used to provide a list of error handlers. They will receive any error thrown during the command process. Error handlers may only be provided *before* the bus is initialized.
func (*Bus) SetInwardMiddlewares ¶ added in v1.3.0
func (bus *Bus) SetInwardMiddlewares(mdls ...InwardMiddleware)
SetInwardMiddlewares may optionally be used to provide a list of inward middlewares. They will receive and process every command that is about to be handled. *The order the middlewares are provided is always respected*. Middlewares may only be provided *before* the bus is initialized.
func (*Bus) SetOutwardMiddlewares ¶ added in v1.3.0
func (bus *Bus) SetOutwardMiddlewares(mdls ...OutwardMiddleware)
SetOutwardMiddlewares may optionally be used to provide a list of outward middlewares. They will receive and process every command that was handled. *The order the middlewares are provided is always respected*. Middlewares may only be provided *before* the bus is initialized.
func (*Bus) SetQueueBuffer ¶ added in v1.3.0
SetQueueBuffer may optionally be used to tweak the buffer size of the async commands queue. This value may have high impact on performance depending on the use case. It can only be adjusted *before* the bus is initialized. It defaults to 100.
func (*Bus) SetWorkerPoolSize ¶ added in v1.3.0
SetWorkerPoolSize may optionally be used to tweak the worker pool size for async commands. It can only be adjusted *before* the bus is initialized. It defaults to the value returned by runtime.GOMAXPROCS(0).
type BusError ¶ added in v1.3.0
type BusError string
BusError is used to create errors originating from the command bus
type ClosureCommand ¶ added in v1.4.0
ClosureCommand is the type used by the bus to handle closures
type Command ¶
type Command interface {
Identifier() Identifier
}
Command is the interface that must be implemented by any type to be considered a command.
type ErrorHandler ¶
ErrorHandler must be implemented for a type to qualify as an error handler.
type Handler ¶
type Handler interface {
Handle(cmd Command) (any, error)
Handles() Identifier
}
Handler must be implemented for a type to qualify as a command handler.
type Identifier ¶ added in v1.3.0
type Identifier int64
Identifier is used to create a consistent identity solution for commands
type InwardMiddleware ¶ added in v1.3.0
InwardMiddleware must be implemented for a type to qualify as an inward command middleware. An inward middleware process a command before being provided to the respective command handler.
type OutwardMiddleware ¶ added in v1.3.0
OutwardMiddleware must be implemented for a type to qualify as an outward command middleware. An outward middleware process the command after being provided to the respective command handler.