eclipse-vertx / eclipse-vertx/vert.x
WebSocket client: make it possible to supply a custom eventLoop context
- Dominant language
- Java
- Stars
- 14.7k
- Forks
- 2.1k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 28
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:
```java
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)` 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: https://github.com/quarkusio/quarkus/pull/44039
Contributor guide
Assessment
This issue has not been assessed yet.