public class SpringCloudCommandRouter extends Object implements CommandRouter
CommandRouter implementation which uses Spring Cloud's
DiscoveryClients to propagate its CommandMessage Routing
Information, and to discover other Axon nodes and retrieve their Message Routing Information.
It does so by utilizing the metadata contained in a ServiceInstance for
storing the Message Routing Information in.
Other nodes discovered through the DiscoveryClient system which do not contain any of the required Message Routing
Information fields will be black listed, so not to perform any unneeded additional checks on that node.| Modifier and Type | Field and Description |
|---|---|
protected XStreamSerializer |
serializer |
| Constructor and Description |
|---|
SpringCloudCommandRouter(org.springframework.cloud.client.discovery.DiscoveryClient discoveryClient,
RoutingStrategy routingStrategy)
Initialize a
CommandRouter with the given DiscoveryClient to update its own membership as a CommandRouter and to create its own awareness of available nodes to send commands to in a ConsistentHash. |
SpringCloudCommandRouter(org.springframework.cloud.client.discovery.DiscoveryClient discoveryClient,
RoutingStrategy routingStrategy,
Predicate<org.springframework.cloud.client.ServiceInstance> serviceInstanceFilter)
Initialize a
CommandRouter with the given DiscoveryClient to update its own membership as a CommandRouter and to create its own awareness of available nodes to send commands to in a ConsistentHash. |
SpringCloudCommandRouter(org.springframework.cloud.client.discovery.DiscoveryClient discoveryClient,
RoutingStrategy routingStrategy,
Serializer serializer)
Deprecated.
serializer is no longer customizable |
| Modifier and Type | Method and Description |
|---|---|
protected SimpleMember<URI> |
buildSimpleMember(org.springframework.cloud.client.ServiceInstance serviceInstance)
|
Optional<Member> |
findDestination(CommandMessage<?> commandMessage)
Returns the member instance to which the given
message should be routed. |
protected Optional<MessageRoutingInformation> |
getMessageRoutingInformation(org.springframework.cloud.client.ServiceInstance serviceInstance)
Retrieve the
MessageRoutingInformation of the provided serviceInstance. |
static boolean |
serviceInstanceMetadataContainsMessageRoutingInformation(org.springframework.cloud.client.ServiceInstance serviceInstance)
Boolean check if the metadata
Map of the given
ServiceInstance contains any of the expected message routing info keys. |
void |
updateMembership(int loadFactor,
Predicate<? super CommandMessage<?>> commandFilter)
Updates the load factor and capabilities of this member representing the current endpoint if the implementation
allows memberships to be updated dynamically.
|
void |
updateMemberships(org.springframework.cloud.client.discovery.event.HeartbeatEvent event) |
protected final XStreamSerializer serializer
@Deprecated public SpringCloudCommandRouter(org.springframework.cloud.client.discovery.DiscoveryClient discoveryClient, RoutingStrategy routingStrategy, Serializer serializer)
serializer is no longer customizableCommandRouter with the given DiscoveryClient to update its own membership as a CommandRouter and to create its own awareness of available nodes to send commands to in a ConsistentHash.
The routingStrategy is used to define the key based on which Command Messages are routed to their
respective handler nodes.
The serializer is used to serialize this node its set of Commands it can handle to be added as meta data
to this ServiceInstance.
Uses a default Predicate<ServiceInstance> filter function to remove any
ServiceInstance which miss message routing information key-value pairs
in their metadata. This is thus the
serviceInstanceMetadataContainsMessageRoutingInformation(ServiceInstance serviceInstance) function.discoveryClient - The DiscoveryClient used to discovery and notify other nodesroutingStrategy - The strategy for routing Commands to a Nodeserializer - The serializer used to serialize this node its set of Commands it can handlepublic SpringCloudCommandRouter(org.springframework.cloud.client.discovery.DiscoveryClient discoveryClient,
RoutingStrategy routingStrategy)
CommandRouter with the given DiscoveryClient to update its own membership as a CommandRouter and to create its own awareness of available nodes to send commands to in a ConsistentHash.
The routingStrategy is used to define the key based on which Command Messages are routed to their
respective handler nodes.
Uses a default Predicate<ServiceInstance> filter function to remove any
ServiceInstance which miss message routing information key-value pairs
in their metadata. This is thus the
serviceInstanceMetadataContainsMessageRoutingInformation(ServiceInstance serviceInstance) function.discoveryClient - The DiscoveryClient used to discovery and notify other nodesroutingStrategy - The strategy for routing Commands to a Nodepublic SpringCloudCommandRouter(org.springframework.cloud.client.discovery.DiscoveryClient discoveryClient,
RoutingStrategy routingStrategy,
Predicate<org.springframework.cloud.client.ServiceInstance> serviceInstanceFilter)
CommandRouter with the given DiscoveryClient to update its own membership as a CommandRouter and to create its own awareness of available nodes to send commands to in a ConsistentHash.
The routingStrategy is used to define the key based on which Command Messages are routed to their
respective handler nodes.
A Predicate<ServiceInstance> to filter a ServiceInstance from
the membership update loop.discoveryClient - The DiscoveryClient used to discovery and notify other nodesroutingStrategy - The strategy for routing Commands to a NodeserviceInstanceFilter - The Predicate<ServiceInstance> used to filter ServiceInstance from the update membership loop.public Optional<Member> findDestination(CommandMessage<?> commandMessage)
CommandRoutermessage should be routed. If no suitable member could be
found an empty Optional is returned.findDestination in interface CommandRoutercommandMessage - the command message to find a member forpublic void updateMembership(int loadFactor,
Predicate<? super CommandMessage<?>> commandFilter)
CommandRouterupdateMembership in interface CommandRouterloadFactor - the new load factor of the member for this endpointcommandFilter - the new capabilities of the member for this endpoint@EventListener public void updateMemberships(org.springframework.cloud.client.discovery.event.HeartbeatEvent event)
protected SimpleMember<URI> buildSimpleMember(org.springframework.cloud.client.ServiceInstance serviceInstance)
SimpleMember of type URI based on the provided serviceInstance.
This SimpleMember is later used to send, for example, Command messages to.serviceInstance - A ServiceInstance to build a SimpleMember
for.SimpleMember based on the contents of the provided serviceInstance.protected Optional<MessageRoutingInformation> getMessageRoutingInformation(org.springframework.cloud.client.ServiceInstance serviceInstance)
MessageRoutingInformation of the provided serviceInstance. If the
MessageRoutingInformation could not be found, an Optional.empty() will be returned. Otherwise the
MessageRoutingInformation will be contained in the Optional.serviceInstance - A ServiceInstance to retrieve MessageRoutingInformation from.Optional of type MessageRoutingInformation, containing the corresponding
MessageRoutingInformation for the given serviceInstance if it could be retrieved.public static boolean serviceInstanceMetadataContainsMessageRoutingInformation(org.springframework.cloud.client.ServiceInstance serviceInstance)
Map of the given
ServiceInstance contains any of the expected message routing info keys.serviceInstance - The ServiceInstance to check its metadata keys
fromserviceInstance contains all expected message routing info keys; false if one
of the expected message routing info keys is missing.Copyright © 2010–2017. All rights reserved.