Class PayloadBasedTagResolver<P>

java.lang.Object
org.axonframework.eventsourcing.eventstore.PayloadBasedTagResolver<P>
Type Parameters:
P - The payload for which to resolve a Set of Tags for.
All Implemented Interfaces:
TagResolver

public class PayloadBasedTagResolver<P> extends Object implements TagResolver
Simple implementation of the TagResolver that is able to combine several lambdas to construct Tags from payloads of type P.

The results of invoking all configured lambdas are combined into the Set of Tags when invoking resolve(EventMessage). The resolve operation defaults to return an empty Set when an EventMessage for another payload type is passed.

Since:
5.0.0
Author:
Steven van Beelen
  • Method Details

    • forPayloadType

      public static <P> PayloadBasedTagResolver<P> forPayloadType(Class<P> payloadType)
      Construct a SimpleTagResolver for the given payloadType.

      The initial resolver does not construct any Tags yet. To add Tags, additional resolvers can be included through withResolver(Function).

      Type Parameters:
      P - The payload for which to resolve a Set of Tags for.
      Parameters:
      payloadType - The Class of the event payload for which to resolve a Set of Tags for.
      Returns:
      A SimpleTagResolver instance start, still requiring resolvers.
    • withResolver

      public PayloadBasedTagResolver<P> withResolver(Function<P,Tag> resolver)
      Construct a copy of this SimpleTagResolver, adding the given resolver to the set.
      Parameters:
      resolver - An additional Function from the event of type P to a Tag.
      Returns:
      A copy of this SimpleTagResolver, adding the given resolver to the set.
    • withResolver

      public PayloadBasedTagResolver<P> withResolver(Function<P,String> keyResolver, Function<P,String> valueResolver)
      Construct a copy of this SimpleTagResolver, combining the given keyResolver and valueResolver into a lambda constructing a Tag.
      Parameters:
      keyResolver - A Function constructing the Tag.key() for a Tag.
      valueResolver - A Function constructing the Tag.value() for a Tag.
      Returns:
      A copy of this SimpleTagResolver, combining the given keyResolver and valueResolver into a lambda constructing a Tag.
    • resolve

      public Set<Tag> resolve(EventMessage event)
      Description copied from interface: TagResolver
      Resolves a Set of Tags for the given event.
      Specified by:
      resolve in interface TagResolver
      Parameters:
      event - The event to resolve a Set of Tags for.
      Returns:
      A Set of Tags for the given event.