Class FallbackEntityIdResolver<ID>

java.lang.Object
org.axonframework.modelling.FallbackEntityIdResolver<ID>
Type Parameters:
ID - the type of the identifier to resolve
All Implemented Interfaces:
DescribableComponent, EntityIdResolver<ID>

public class FallbackEntityIdResolver<ID> extends Object implements EntityIdResolver<ID>, DescribableComponent
An EntityIdResolver implementation composing two others, a primary resolver invoked first and a secondary resolver is invoked only if the primary fails to resolve an identifier.

Useful when a single message type can carry its identifier in more than one way, for example, a AnnotationBasedEntityIdResolver for messages whose payload carries a TargetEntityId-annotated member, falling back to a MetadataEntityIdResolver for messages that do not.

Since:
5.4.0
Author:
Steven van Beelen
See Also:
  • Constructor Details

    • FallbackEntityIdResolver

      public FallbackEntityIdResolver(EntityIdResolver<ID> primary, EntityIdResolver<ID> secondary)
      Initializes the resolver, trying the given primary resolver before the given secondary resolver.
      Parameters:
      primary - the EntityIdResolver to resolve the identifier with first
      secondary - the EntityIdResolver to resolve the identifier with when the primary fails
  • Method Details

    • resolve

      public ID resolve(Message message, ProcessingContext context) throws EntityIdResolutionException
      Description copied from interface: EntityIdResolver
      Resolve the id of the entity from the given message and context.
      Specified by:
      resolve in interface EntityIdResolver<ID>
      Parameters:
      message - The message to resolve the id from.
      context - The context in which the message is processed.
      Returns:
      The id of the entity.
      Throws:
      EntityIdResolutionException - When the id could not be resolved.
    • describeTo

      public void describeTo(ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.