Package dk.cloudcreate.essentials.reactive.command
package dk.cloudcreate.essentials.reactive.command
-
ClassDescriptionBase implementation of the
CommandBus- provides default implementation for all operations except forCommandBus.sendAndDontWait(Object)/CommandBus.sendAndDontWait(Object, Duration)Extending this class will allow you to colocate multiple related Command handling methods inside the same class and use it together with theLocalCommandBus
Each method must accept a single Command argument, may return a value or return void and be annotated with either theHandlerorCmdHandlerannotation.
The method argument type is matched against the concrete command type usingClass.isAssignableFrom(Class).
The method accessibility can be any combination of private, protected, public, etc.
Example:AnnotatedCommandHandlerspecific method annotation, that can be used instead ofHandler, that can be applied to any single argument method inside aAnnotatedCommandHandler
The annotated methods can have the following accessibility: private, protected, public, etc.TheCommandBusprovides an indirection between a command and theCommandHandlerthat's capable of handling the command.
Commands can be sent synchronously usingCommandBus.send(Object)or asynchronously usingCommandBus.sendAsync(Object)that returns aMono.
The handling of a command usually doesn't return any value (according to the principles of CQRS), however theLocalCommandBusAPI allows aCommandHandlerto return a value if needed (e.g. such as a server generated id)
One important rule is that there can only be oneCommandHandlerinstance that can handle any given command type.
If multipleCommandHandlerclaim that they all can handle a given command type thenCommandBus.send(Object)/CommandBus.sendAsync(Object)will throwMultipleCommandHandlersFoundException
If noCommandHandler's can handle the given command type thenCommandBus.send(Object)/CommandBus.sendAsync(Object)will throwNoCommandHandlerFoundExceptionCommon interface for all Command message handlers
A command handler can choose support to 1 or more command typesProvides a JVM local and non-durable, in regard toLocalCommandBus.sendAndDontWait(Object)/LocalCommandBus.sendAndDontWait(Object, Duration)), variant of theCommandBusconceptException handler that will handle errors that occur duringCommandBus.sendAndDontWait(Object)/CommandBus.sendAndDontWait(Object, Duration)FallbackSendAndDontWaitErrorHandlerthat only error logs any issues.
Note: If theSendAndDontWaitErrorHandler.FallbackSendAndDontWaitErrorHandleris used with a Durable Command Bus (e.g. using DurableQueues), then any failing command will not be retried.
Instead useSendAndDontWaitErrorHandler.RethrowingSendAndDontWaitErrorHandlerFallbackSendAndDontWaitErrorHandlerthat error logs any issues and rethrows the exception.
TheSendAndDontWaitErrorHandler.RethrowingSendAndDontWaitErrorHandleris compatible with a Durable Command Bus (e.g. using DurableQueues), as rethrowing the exceptions allows the command to be retried