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.

@FunctionalInterface public interface CommandTargetResolver<E>
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 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 null if no child entity is found that can handle the command. In that case, the CommandTargetResolver should 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 null if no suitable entity is found.
    • MATCH_ANY

      static <C> CommandTargetResolver<C> MATCH_ANY()
      Returns a CommandTargetResolver that matches any child entity. This means it will return the first candidate child entity if there is one, or throw a ChildAmbiguityException if there are multiple candidates. If there are no candidates, it will return null.
      Type Parameters:
      C - The type of child entity to resolve.
      Returns:
      A CommandTargetResolver that matches any child entity.