Annotation Interface EntityMember


@Documented @Target({FIELD,METHOD,ANNOTATION_TYPE}) @Retention(RUNTIME) public @interface EntityMember
Annotation placed on fields or methods of an entity that should be treated as a child entity. Messages are filtered based on the eventTargetMatcher() and commandTargetResolver(), which both default to a matcher based on the routingKey().

The default routing key matcher and resolver will match a property on the child entity annotated with RoutingKey to a property of the message. The message property defaults to the name of the property in the entity, but can be overridden through routingKey().

A RoutingKey property is required in all collection child entities when using the RoutingKeyEventTargetMatcher as the eventForwardingMode or commandForwardingMode. For singular child entities (not backed by an Iterable), this can be omitted.

Note that this annotation existed as org.axonframework.modelling.command.AggregateMember before version 5.0.0. Besides the change in name to align better with the entities instead of aggregates, the version introduced the commandTargetResolver(), which before was not configurable.

Since:
3.0.0
Author:
Allard Buijze, Mitchell Herrijgers
  • Element Details

    • routingKey

      String routingKey
      The routing key to use for matching messages to this child entity. Defaults to an empty string, which means the name of the RoutingKey-annotated property in the child entity will be used as the routing key.
      Returns:
      The routing key to use for matching messages to this child entity.
      Default:
      ""
    • eventTargetMatcher

      Class<? extends EventTargetMatcherDefinition> eventTargetMatcher
      The EventTargetMatcher is used to determine which entity should be evolved by the EventMessage. The forwarding mode can match 0, 1, or multiple child entities, and as such functions like a predicate or filter.

      Defaults to using the RoutingKeyEventTargetMatcher, which matches messages based on the routing key. Users can choose to create their own definition, and thus their own forwarding mode, that has specific routing logic.

      Returns:
      The class defining the EventTargetMatcher for this child entity.
      Default:
      org.axonframework.modelling.entity.annotation.RoutingKeyEventTargetMatcherDefinition.class
    • commandTargetResolver

      Class<? extends CommandTargetResolverDefinition> commandTargetResolver
      The CommandTargetResolverDefinition is used to determine to which of the child entities a CommandMessage should be forwarded. The result should always be a single child entity, or no child entity at all, as command can only be handled by a single entity.

      The result can also be null to indicate that no child entity should handle the command. This allows users to declare multiple fields with the same child entity type, but with different RoutingKey properties, and thus different routing logic for commands.

      Defaults to using the RoutingKeyCommandTargetResolverDefinition, which matches messages based on the routing key. Users can choose to create their own definition, and thus their own forwarding mode, that has specific routing logic.

      Returns:
      The class defining CommandTargetResolver for this child entity.
      Default:
      org.axonframework.modelling.entity.annotation.RoutingKeyCommandTargetResolverDefinition.class