Package io.quarkus.websockets.next
Annotation Interface OnTextMessage
@Retention(RUNTIME)
@Target(METHOD)
@Experimental("This API is experimental and may change in the future")
public @interface OnTextMessage
WebSocket and WebSocketClient endpoint methods annotated with this annotation consume text messages. An
endpoint may declare at most one method annotated with this annotation.
Execution model
- Methods annotated with
RunOnVirtualThreadare considered blocking and should be executed on a virtual thread. - Methods annotated with
Blockingare considered blocking and should be executed on a worker thread. - Methods annotated with
NonBlockingare considered non-blocking and should be executed on an event loop thread.
- Methods returning
voidare considered blocking and should be executed on a worker thread. - Methods returning
UniorMultiare considered non-blocking and should be executed on an event loop thread. - Methods returning any other type are considered blocking and should be executed on a worker thread.
Method parameters
The method must accept exactly one message parameter. A text message is always represented as aString. Therefore,
the following conversion rules apply. The types listed below are handled specifically. For all other types a
TextMessageCodec is used to encode and decode input and output messages. By default, the first input codec that
supports the message type is used; codecs with higher priority go first. However, a specific codec can be selected with
codec() and outputCodec().
java.lang.Stringis used as is,io.vertx.core.json.JsonObjectis encoded withJsonObject.encode()and decoded with {@link io.vertx.core.json.JsonObject#JsonObject(String))}.io.vertx.core.json.JsonArrayis encoded withJsonArray.encode()and decoded with {@link io.vertx.core.json.JsonArray#JsonArray(String))}.java.lang.Bufferis encoded withBuffer.toString()and decoded withBuffer.buffer(String),byte[]is first converted toBufferand then converted as defined above.
WebSocketConnection/WebSocketClientConnection; depending on the endpoint typeHandshakeRequestStringparameters annotated withPathParam
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanBroadcasting is only supported for server endpoints annotated withWebSocket.Class<? extends TextMessageCodec>The codec used for input messages.Class<? extends TextMessageCodec>The codec used for output messages.
-
Element Details
-
broadcast
boolean broadcastBroadcasting is only supported for server endpoints annotated withWebSocket.- Returns:
trueif all the connected clients should receive the objects returned by the annotated method- See Also:
- Default:
- false
-
codec
Class<? extends TextMessageCodec> codecThe codec used for input messages.By default, the first codec that supports the message type is used; codecs with higher priority go first. Note that, if specified, the codec is also used for output messages unless
outputCodec()returns a non-default value.- Default:
- io.quarkus.websockets.next.TextMessageCodec.class
-
outputCodec
Class<? extends TextMessageCodec> outputCodecThe codec used for output messages.By default, the same codec as for the input message is used.
- Default:
- io.quarkus.websockets.next.TextMessageCodec.class
-