Description
As discussed on Discord it would make sense to add the possibility to supply a custom eventLoop context when a new WebSocket is connected.
Currently, when you connect a new Websocket it takes the current context that is used to send messages etc. This means that if you connect multiple clients in a row they will use the same event loop and so writing/receiving messages is de facto serialized.
The workaround is to create a new eventLoop context and dispatch the connection logic:
Context context = ((VertxImpl) vertx).createEventLoopContext();
context.dispatch(v -> {
// vertx.createWebSocketClient().connect()...
}
In Vertx4, we could add the eventLoopContext
to the WebSocketConnectOptions
and then use it in HttpClientBase#webSocket(WebSocketConnectOptions, PromiseInternal<WebSocket>)
if not null
. Alternatively, we could add something like io.vertx.core.http.impl.WebSocketClientImpl#webSocket(ContextInternal)
.
Use cases
In Quarkus, we will use the aforementioned workaround in the mean time: quarkusio/quarkus#44039