After upgrading from 4.3.2 to Vert.X 4.4.1, webSocket.textHandlerID() is now null.
The release notes tell that we can switch back to the previous behavior via WebSocketConnectOptions but this only seems to be possible when using a Vert.X HTTP client, or am I missing something here?
How can I switch back to the previous behavior which allowed me to use webSocket.textHandlerID() when using a non-Vert.X client (e.g. React JS client) connecting to the Vert.X HTTP endpoint?
Context
I'm using httpServerRequest.toWebsocket() to upgrade an HTTP connection to a WebSocket connection on the server-side and then use the WebSocket opened by Vert.X to stream messages to my React JS client.
To do so, I'm using webSocket.textHandlerID() in Handler<RoutingContext>.handle(context) to get the Websocket address of the opened socket.
Expected
I expected webSocket.textHandlerID() to not change, or find a Vert.X option on the server-side to switch back to the pre-4.4 behavior.
You can solve this problem with the example below:
vertx.createHttpServer(new HttpServerOptions()
.setRegisterWebSocketWriteHandlers(true))
.webSocketHandler(new WebSocketHandler())
.listen(PORT, http -> {
if (http.succeeded()) {
startPromise.complete();
LOG.info("HTTP server started on port {}", PORT);
} else {
startPromise.fail(http.cause());
}});
The reason is explained in the doc:
By default, no handler is registered, the feature must be enabled via {@link WebSocketConnectOptions#setRegisterWriteHandlers(boolean)} or {@link HttpServerOptions#setRegisterWebSocketWriteHandlers(boolean)}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With