Package io.quarkus.vertx
Annotation 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
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
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
-
Optional Element Summary
Optional Elements -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFailure code used when a message consumer explicitly fails an asynchronous processing.static final intFailure code used when a message consumer method throws an exception.
-
Field Details
-
FAILURE_CODE
static final int FAILURE_CODEFailure code used when a message consumer method throws an exception.- See Also:
-
EXPLICIT_FAILURE_CODE
static final int EXPLICIT_FAILURE_CODEFailure code used when a message consumer explicitly fails an asynchronous processing. This status is used when the method annotated withConsumeEventreturns a failedCompletionStageorUni.- See Also:
-
-
Element Details
-
value
String valueThe 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:
trueif the address should not be propagated across the cluster- See Also:
-
EventBus.localConsumer(String)
- Default:
- true
-
blocking
boolean blocking- Returns:
trueif 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:
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(Callable, boolean)
- Default:
- false
-
codec
Class<? extends io.vertx.core.eventbus.MessageCodec> codec- Returns:
nullif it should use a default MessageCodec- See Also:
- Default:
- io.quarkus.vertx.LocalEventBusCodec.class
-