Annotation Type ConsumeEvent


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

    The method must accept exactly one parameter. If it accepts 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("echoMessage")
         void echoMessage(Message msg) {
             msg.reply(msg.body().toUpperCase());
         }
     
         @ConsumeEvent(value = "echoMessageBlocking", blocking = true)
         void echoMessageBlocking(Message msg) {
             msg.reply(msg.body().toUpperCase());
         }
     }
     

    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
    • Field Summary

      Fields 
      Modifier and Type Fields Description
      static int EXPLICIT_FAILURE_CODE
      Failure code used when a message consumer explicitly fails an asynchronous processing.
      static int FAILURE_CODE
      Failure code used when a message consumer method throws an exception.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean blocking  
      Class<? extends io.vertx.core.eventbus.MessageCodec> codec  
      boolean local  
      boolean ordered  
      String value
      The address the consumer will be registered to.
    • Field Detail

      • FAILURE_CODE

        static final int FAILURE_CODE
        Failure code used when a message consumer method throws an exception.
      • 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.
    • Element Detail

      • value

        String value
        The address the consumer will be registered to. By default, the fully qualified name of the declaring bean class is assumed.
        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(io.vertx.core.Handler, boolean, io.vertx.core.Handler)
        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(io.vertx.core.Handler, boolean, io.vertx.core.Handler)
        Default:
        false
      • codec

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