Class MetadataEntityIdResolver<ID>

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

public class MetadataEntityIdResolver<ID> extends Object implements EntityIdResolver<ID>, DescribableComponent
An EntityIdResolver implementation that resolves the identifier from a Message's Metadata.

Useful when the payload itself does not carry the identifier of the entity to target. For example, a message translated from another model that only knows the target identifier out-of-band. The identifier is resolved by looking up the given key in the message's metadata. If the key is absent, or maps to a blank value, a EntityIdResolutionException is thrown.

Metadata values are always Strings. The forKey(String) factory method enforces this: it assumes ID to be String itself, returning the metadata value unconverted. To resolve an identifier of another type, a String-converted identifier can be converted back to the required type. For that, use forKey(String, Class, Converter).

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

    • forKey

      public static MetadataEntityIdResolver<String> forKey(String key)
      Constructs a MetadataEntityIdResolver resolving the identifier from the given key, enforcing ID to be String.
      Parameters:
      key - the name of the metadata entry to resolve the identifier from
      Returns:
      a MetadataEntityIdResolver resolving a String identifier from the given key
    • forKey

      public static <ID> MetadataEntityIdResolver<ID> forKey(String key, Class<ID> idType, Converter converter)
      Constructs a MetadataEntityIdResolver resolving the identifier from the given key, converting the resolved metadata value into the given idType using the given converter.
      Type Parameters:
      ID - the type of the identifier to resolve
      Parameters:
      key - the name of the metadata entry to resolve the identifier from
      idType - the type to convert the resolved metadata value into
      converter - the Converter to convert the resolved metadata value with
      Returns:
      a MetadataEntityIdResolver resolving an identifier of the given idType from the given key
    • 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.