Class MetadataEntityIdResolver<ID>
- Type Parameters:
ID- the type of the identifier to resolve
- All Implemented Interfaces:
DescribableComponent,EntityIdResolver<ID>
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 Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.static MetadataEntityIdResolver<String> Constructs aMetadataEntityIdResolverresolving the identifier from the givenkey, enforcingIDto beString.static <ID> MetadataEntityIdResolver<ID> Constructs aMetadataEntityIdResolverresolving the identifier from the givenkey, converting the resolved metadata value into the givenidTypeusing the givenconverter.resolve(Message message, ProcessingContext context) Resolve the id of the entity from the givenmessageandcontext.
-
Method Details
-
forKey
Constructs aMetadataEntityIdResolverresolving the identifier from the givenkey, enforcingIDto beString.- Parameters:
key- the name of the metadata entry to resolve the identifier from- Returns:
- a
MetadataEntityIdResolverresolving aStringidentifier from the givenkey
-
forKey
public static <ID> MetadataEntityIdResolver<ID> forKey(String key, Class<ID> idType, Converter converter) Constructs aMetadataEntityIdResolverresolving the identifier from the givenkey, converting the resolved metadata value into the givenidTypeusing the givenconverter.- Type Parameters:
ID- the type of the identifier to resolve- Parameters:
key- the name of the metadata entry to resolve the identifier fromidType- the type to convert the resolved metadata value intoconverter- theConverterto convert the resolved metadata value with- Returns:
- a
MetadataEntityIdResolverresolving an identifier of the givenidTypefrom the givenkey
-
resolve
Description copied from interface:EntityIdResolverResolve the id of the entity from the givenmessageandcontext.- Specified by:
resolvein interfaceEntityIdResolver<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
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods 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
DescribableComponentimplementation 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 thedescribeTomethod, 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:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-