Interface CommandTargetResolver<E>
- Type Parameters:
E- The type of child entity to resolve.
- All Known Implementing Classes:
RoutingKeyCommandTargetResolver
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Resolves the target child entity for a given command message. This is used to determine which child entity should
handle a command when one multiple child entities are present.
- Since:
- 5.0.0
- Author:
- Mitchell Herrijgers
-
Method Summary
Modifier and TypeMethodDescriptiongetTargetChildEntity(List<E> candidates, CommandMessage message, ProcessingContext context) Returns the target child entity for the given command message.static <C> CommandTargetResolver<C> Returns aCommandTargetResolverthat matches any child entity.
-
Method Details
-
getTargetChildEntity
@Nullable E getTargetChildEntity(@Nonnull List<E> candidates, @Nonnull CommandMessage message, @Nonnull ProcessingContext context) Returns the target child entity for the given command message. This method is called when multiple child entities are present and the command needs to be routed to the correct one.Can return
nullif no child entity is found that can handle the command. In that case, theCommandTargetResolvershould not throw an exception, but rather allow the command to be handled by another child entity.- Parameters:
candidates- The list of candidate child entities that can handle the command.message- The command message to resolve the target child entity for.context- The processing context in which the command is being processed.- Returns:
- The target child entity that should handle the command, or
nullif no suitable entity is found.
-
MATCH_ANY
Returns aCommandTargetResolverthat matches any child entity. This means it will return the first candidate child entity if there is one, or throw aChildAmbiguityExceptionif there are multiple candidates. If there are no candidates, it will returnnull.- Type Parameters:
C- The type of child entity to resolve.- Returns:
- A
CommandTargetResolverthat matches any child entity.
-