Annotation Interface ConsumeEvent


@Target(METHOD) @Retention(RUNTIME) public @interface ConsumeEvent
Marks a business method to be automatically registered as a Vertx message consumer.

The method can accept the following parameters:

  • io.vertx.core.eventbus.Message message
  • io.vertx.mutiny.core.eventbus.Message message
  • MultiMap headers, T body
  • T body
If it accepts a Message then the return type must be void. For any other type the Message.body() is passed as the parameter value and the method may return an object that is passed to Message.reply(Object), either directly or via CompletionStage.thenAccept(java.util.function.Consumer) in case of the method returns a completion stage.
 @ApplicationScoped
 class MyService {

     @ConsumeEvent("echo")
     String echo(String msg) {
         return msg.toUpperCase();
     }

     @ConsumeEvent("echoHeaders")
     String echo(MultiMap headers, String msg) {
         return msg.toUpperCase();
     }

     @ConsumeEvent("echoMessage")
     void echoMessage(Message msg) {
         msg.reply(msg.body().toUpperCase());
     }

     @ConsumeEvent(value = "echoMessageBlocking", blocking = true)
     void echoMessageBlocking(Message msg) {
         msg.reply(msg.body().toUpperCase());
     }
 }
 
If it accepts a Message.headers() then the first parameters must be the headers and the second parameter must be the Message.body().
 @ConsumeEvent("echoHeaders")
 String event(MultiMap headers, String msg) {
     String traceId = headers.get("traceId");
     return "Message is: " + msg + ", trace is: " + traceId;
 }
 
The CDI request context is always active during notification of the registered message consumer.

If a method annotated with ConsumeEvent throws an exception then:

  • if a reply handler is set the failure is propagated back to the sender via an ReplyException with code FAILURE_CODE and the exception message,
  • if no reply handler is set then the exception is rethrown (and wrapped in a RuntimeException if necessary) and can be handled by the default exception handler, i.e. {@link io.vertx.core.Vertx#exceptionHandler().}
See Also:
  • EventBus
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
     
    Class<? extends io.vertx.core.eventbus.MessageCodec>
     
    boolean
     
    boolean
     
    The address the consumer will be registered to.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Failure code used when a message consumer explicitly fails an asynchronous processing.
    static final int
    Failure code used when a message consumer method throws an exception.
  • Field Details

    • FAILURE_CODE

      static final int FAILURE_CODE
      Failure code used when a message consumer method throws an exception.
      See Also:
    • EXPLICIT_FAILURE_CODE

      static final int EXPLICIT_FAILURE_CODE
      Failure code used when a message consumer explicitly fails an asynchronous processing. This status is used when the method annotated with ConsumeEvent returns a failed CompletionStage or Uni.
      See Also:
  • Element Details

    • value

      String value
      The address the consumer will be registered to. By default, the fully qualified name of the declaring bean class is assumed.

      The value can be a config property expression. In this case, the configured value is used instead: @ConsumeEvent("${my.consumer.address}"). Additionally, the property expression can specify a default value: @ConsumeEvent("${my.consumer.address:defaultAddress}").

      Returns:
      the address
      Default:
      ""
    • local

      boolean local
      Returns:
      true if the address should not be propagated across the cluster
      See Also:
      • EventBus.localConsumer(String)
      Default:
      true
    • blocking

      boolean blocking
      Returns:
      true if the consumer should be invoked as a blocking operation using a worker thread
      See Also:
      • Vertx.executeBlocking(Callable, boolean)
      Default:
      false
    • ordered

      boolean ordered
      Returns:
      true if the blocking consumption of the event must be ordered, meaning that the method won't be called concurrently. Instead, it serializes all the invocations based on the event order. ordered must be used in conjunction with blocking=true or @Blocking.
      See Also:
      • Vertx.executeBlocking(Callable, boolean)
      Default:
      false
    • codec

      Class<? extends io.vertx.core.eventbus.MessageCodec> codec
      Returns:
      null if it should use a default MessageCodec
      See Also:
      Default:
      io.quarkus.vertx.LocalEventBusCodec.class