axon-springcloud
module is available on the classpath. The easiest way is to include the Spring Cloud starter (axon-springcloud-spring-boot-starter
) from this extension to your project.SpringCloudCommandRouter
and a SpringHttpCommandBusConnector
. The former is the CommandRouter
and latter the CommandBusConnector
, both used by the DistributedCommandBus
to enable command distribution.SpringCloudCommandRouter
uses Spring Cloud's discovery mechanism to find the other nodes in the cluster. To that end it uses the DiscoveryClient
and Registration
from Spring Cloud. These are respectively used to gather remote command routing information and maintain local information. The most straightforward way to retrieve both is by annotating your application with @EnableDiscoveryClient
.ServiceInstance
s. A Registration
is just the local ServiceInstance
, whereas the DiscoveryClient
provides the API to find remote ServiceInstance
s. Furthermore, it is the ServiceInstance
which provides us with the required information (e.g. the URI) to retrieve a node's capabilities.Spring Cloud's Heartbeat RequirementWhen using theSpringCloudCommandRouter
, make sure your Spring application has heartbeat events enabled. The heartbeat events published by a Spring Cloud application are the trigger to check if the set ofServiceInstance
s from theDiscoveryClient
has been changed. Additionally, it is used to validate whether the command routing capabilities for known nodes has been altered.Thus, if heartbeat events are disabled, your instance will no longer be updated with the current command routing capabilities. If so, this will cause issues during command routing.
ServiceInstance
is maintained in the CapabilityDiscoveryMode
. It is thus the CapabilityDiscoveryMode
which provides us the means to actually retrieve a ServiceInstance
's set of commands it can handle (if any). The sole full implementation provided of the CapabilityDiscoveryMode
, is the RestCapabilityDiscoveryMode
, using a RestTemplate
and the ServiceInstance
URI to invoke a configurable endpoint. This endpoint leads to the MemberCapabilitiesController
which in turn exposes the MemberCapabilities
on the RestCapabilityDiscoveryMode
of that instance.CapabilityDiscoveryMode
, providing two additional features:IgnoreListingDiscoveryMode
- a CapabilityDiscoveryMode
decorator which on failure of retrieving the MemberCapabilities
will place the given ServiceInstance
on a list to be ignored for future validation. It thus effectively removes discoverable ServiceInstance
s from the set.AcceptAllCommandsDiscoveryMode
- a CapabilityDiscoveryMode
decorator which regardless of what this instance can handle as commands, state it can handle anything. This decorator comes in handy if the nodes in the system are homogeneous (aka, everybody can handle the same set of commands).Registration
, DiscoveryClient
and CapabilityDiscoveryMode
are arguably the heart of the SpringCloudCommandRouter
. There are, however, a couple of additional things you can configure for this router, which are the following:RoutingStrategy
- The component in charge of deciding which of the nodes receives the commands consistently. By default, a AnnotationRoutingStrategy
is used (see Distributing the Command Bus for more).ServiceInstance
filter - This Predicate
is used to filter out ServiceInstance
s retrieved through the DiscoveryClient
. For example, it allows the removal of instances which are known to not handle any command messages. This might be useful if you have several services within the Spring Cloud Discovery Service set up, which you do not ever want to take into account for command handling.ConsistentHashChangeListener
- Adding a consistent hash change listener provides you with the opportunity to perform a specific task if new nodes have been added to the known command handlers set.Differing Command Capabilities per NodeIt is not required for all nodes to have the same set of command handlers. You may use different segments for different command types altogether. The Distributed Command Bus will always choose a node to dispatch a command to the one that has support for that specific type of command.
CommandBusConnector
is in charge of sending commands, based on a given route, from one node to another. This extension to that end provides the SpringHttpCommandBusConnector
, which uses plain REST for sending commands.CommandBus
- This "local segment" is the command bus which dispatches commands into the local JVM. It is thus invoked when the SpringHttpCommandBusConnector
receives a command from the outside, or if it receives a command which is meant for itself.RestOperations
- The service used to POST a command message to another instance. In most situations the RestTemplate
is used for this.Serializer
- The serializer is used to serialize the command messages before they are sent over and deserialize when they are received.Executor
(optional) - The Executor
is used to handle incoming commands and to dispatch commands. Defaults to a DirectExecutor
instance.axon-springcloud-spring-boot-starter
dependency to automatically retrieve all required beans. In either case, your application should be marked to enable it as a discoverable service through Spring Cloud. This can, for example, be done by annotating the main class with @EnableDiscoveryClient
.