Interface BasicWebSocketConnector
- All Known Implementing Classes:
BasicWebSocketConnectorImpl
WebSocketConnector a
client endpoint is not used to consume and send messages.
Quarkus provides a CDI bean with bean type BasicWebSocketConnector and qualifier Default.
This construct is not thread-safe and should not be used concurrently.
Connectors should not be reused. If you need to create multiple connections in a row you'll need to obtain a new connetor
instance programmatically using Provider.get():
import jakarta.enterprise.inject.Instance;
@Inject
Instance<BasicWebSocketConnector> connector;
void connect() {
var connection1 = connector.get().baseUri(uri)
.addHeader("Foo", "alpha")
.connectAndAwait();
var connection2 = connector.get().baseUri(uri)
.addHeader("Foo", "bravo")
.connectAndAwait();
}
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionAdd a header used during the initial handshake request.addSubprotocol(String value) Add the subprotocol.default BasicWebSocketConnectorSet the base URI.Set the base URI.io.smallrye.mutiny.Uni<WebSocketClientConnection> connect()default WebSocketClientConnectionstatic BasicWebSocketConnectorcreate()Obtains a new basic connector.customizeOptions(BiConsumer<io.vertx.core.http.WebSocketConnectOptions, io.vertx.core.http.WebSocketClientOptions> customizer) This method allows to customizeWebSocketConnectOptionsandWebSocketClientOptions.Set the execution model for callback handlers.onBinaryMessage(BiConsumer<WebSocketClientConnection, io.vertx.core.buffer.Buffer> consumer) Set a callback to be invoked when a binary message is received from the server.onClose(BiConsumer<WebSocketClientConnection, CloseReason> consumer) Set a callback to be invoked when a connection to the server is closed.onError(BiConsumer<WebSocketClientConnection, Throwable> consumer) Set a callback to be invoked when an error occurs.onOpen(Consumer<WebSocketClientConnection> consumer) Set a callback to be invoked when a connection to the server is open.onPing(BiConsumer<WebSocketClientConnection, io.vertx.core.buffer.Buffer> consumer) Set a callback to be invoked when a ping message is received from the server.onPong(BiConsumer<WebSocketClientConnection, io.vertx.core.buffer.Buffer> consumer) Set a callback to be invoked when a pong message is received from the server.onTextMessage(BiConsumer<WebSocketClientConnection, String> consumer) Set a callback to be invoked when a text message is received from the server.Set the path that should be appended to the path of the URI set bybaseUri(URI).Set the path param.tlsConfigurationName(String tlsConfigurationName) Set the name of theTlsConfiguration.<VALUE> BasicWebSocketConnectoruserData(UserData.TypedKey<VALUE> key, VALUE value) Add a value to the connection user data.
-
Method Details
-
create
Obtains a new basic connector. An alternative to@Inject BasicWebSocketConnector.- Returns:
- a new basic connector
-
baseUri
Set the base URI.- Parameters:
uri-- Returns:
- self
-
baseUri
Set the base URI.- Parameters:
baseUri-- Returns:
- self
-
tlsConfigurationName
Set the name of theTlsConfiguration.- Parameters:
tlsConfigurationName-- Returns:
- self
- See Also:
-
path
Set the path that should be appended to the path of the URI set bybaseUri(URI).The path may contain path parameters as defined by
WebSocketClient.path(). In this case, thepathParam(String, String)method must be used to pass path param values.- Parameters:
path-- Returns:
- self
-
pathParam
Set the path param.The value is encoded using
URLEncoder.encode(String, java.nio.charset.Charset)before it's used to build the target URI.- Parameters:
name-value-- Returns:
- self
- Throws:
IllegalArgumentException- If the path set bypath(String)does not contain a parameter with the given name
-
addHeader
Add a header used during the initial handshake request.- Parameters:
name-value-- Returns:
- self
- See Also:
-
addSubprotocol
Add the subprotocol.- Parameters:
value-name-- Returns:
- self
-
userData
Add a value to the connection user data.- Type Parameters:
VALUE-- Parameters:
key-value-- Returns:
- self
- See Also:
-
executionModel
Set the execution model for callback handlers.By default,
BasicWebSocketConnector.ExecutionModel.BLOCKINGis used.- Returns:
- self
- See Also:
-
onOpen
Set a callback to be invoked when a connection to the server is open.- Parameters:
consumer-- Returns:
- self
- See Also:
-
onTextMessage
Set a callback to be invoked when a text message is received from the server.- Parameters:
consumer-- Returns:
- self
- See Also:
-
onBinaryMessage
BasicWebSocketConnector onBinaryMessage(BiConsumer<WebSocketClientConnection, io.vertx.core.buffer.Buffer> consumer) Set a callback to be invoked when a binary message is received from the server.- Parameters:
consumer-- Returns:
- self
- See Also:
-
onPing
BasicWebSocketConnector onPing(BiConsumer<WebSocketClientConnection, io.vertx.core.buffer.Buffer> consumer) Set a callback to be invoked when a ping message is received from the server.- Parameters:
consumer-- Returns:
- self
- See Also:
-
onPong
BasicWebSocketConnector onPong(BiConsumer<WebSocketClientConnection, io.vertx.core.buffer.Buffer> consumer) Set a callback to be invoked when a pong message is received from the server.- Parameters:
consumer-- Returns:
- self
- See Also:
-
onClose
Set a callback to be invoked when a connection to the server is closed.- Parameters:
consumer-- Returns:
- self
- See Also:
-
onError
Set a callback to be invoked when an error occurs.- Parameters:
consumer-- Returns:
- self
- See Also:
-
connect
- Returns:
- a new
Uniwith aWebSocketClientConnectionitem
-
connectAndAwait
- Returns:
- the client connection
-
customizeOptions
BasicWebSocketConnector customizeOptions(BiConsumer<io.vertx.core.http.WebSocketConnectOptions, io.vertx.core.http.WebSocketClientOptions> customizer) This method allows to customizeWebSocketConnectOptionsandWebSocketClientOptions. Connection options configured directly with this API, such as host and port, have higher priority than this customizer. Client options configured directly with Quarkus configuration (e.g. if you configure the maximum size of a frame) have also higher priority than this customizer. Purpose of this customizer is to complement configuration options not configured elsewhere.- Parameters:
customizer- options customizer; must not be null- Returns:
- self
-