Package io.quarkus.vertx
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 can accept the following parameters:
io.vertx.core.eventbus.Messagemessageio.vertx.mutiny.core.eventbus.MessagemessageMultiMapheaders,TbodyTbody
Messagethen the return type must be void. For any other type theMessage.body()is passed as the parameter value and the method may return an object that is passed toMessage.reply(Object), either directly or viaCompletionStage.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(MessageIf it accepts amsg) { msg.reply(msg.body().toUpperCase()); } @ConsumeEvent(value = "echoMessageBlocking", blocking = true) void echoMessageBlocking(Message msg) { msg.reply(msg.body().toUpperCase()); } } Message.headers()then the first parameters must be the headers and the second parameter must be theMessage.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
ConsumeEventthrows an exception then:- if a reply handler is set the failure is propagated back to the sender via an
ReplyExceptionwith codeFAILURE_CODEand the exception message, - if no reply handler is set then the exception is rethrown (and wrapped in a
RuntimeExceptionif 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 intEXPLICIT_FAILURE_CODEFailure code used when a message consumer explicitly fails an asynchronous processing.static intFAILURE_CODEFailure 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 withConsumeEventreturns a failedCompletionStageorUni.
-
-
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:
- ""
-
-
-
ordered
boolean ordered
- Returns:
trueif 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.orderedmust be used in conjunction withblocking=trueor@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:
nullif it should use a default MessageCodec- See Also:
LocalEventBusCodec
- Default:
- io.quarkus.vertx.LocalEventBusCodec.class
-
-