Annotation Interface RoutingKey


@Target({METHOD,FIELD,TYPE}) @Retention(RUNTIME) public @interface RoutingKey
Annotation used to identify the routing key of a message, which in turn is used to compute the message segment using consistent hashing. If the routing key and thus segment of two messages are equal, the messages are always given to a consumer in order. Often, this is used to ensure that messages about the same subject (say one aggregate), aren't handled in parallel to prevent concurrent modifications.

This annotation can be used as a field, method or type annotation in a payload class. If placed on a method, that method must contain no parameters. If it is on a field or getter method it uses the property to obtain the routing key. The value of the property will be converted to a string via the value's toString() method.

If the annotation is used at the class level of the payload class, a property name should be specified using value(). That property will first be looked up inside the message's Metadata. If it is not found there, the property will be looked for inside the payload. In that case, the property name may also contain one or more slashes ('/') if the property is hiding inside an embedded field.

Finally, it is also possible to place this annotation on a handler method. In that case, the property name specified by value() of the payload (metadata or payload property) will be used to compute the routing key before handling. This effectively overrides any routing key computed upon publication of the message. Important note: if the annotation is on a handler method, make sure the consumer configuration has ignoreSegment = true; otherwise messages may be missed by the consumer.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Returns the metadata key or property name to use to look up the routing key.
  • Element Details

    • value

      String value
      Returns the metadata key or property name to use to look up the routing key. If left empty, the annotated field or method will be used to determine the routing key.
      Default:
      ""