gnodet opened a new pull request, #27764:
URL: https://github.com/apache/camel/pull/27764

   ## Summary
   
   When a `VertxWebsocketClientConsumer` starts and the endpoint's WebSocket is 
already open — because a producer on the same endpoint connected first, or the 
consumer route was stopped and restarted while the server remained healthy — 
the consumer registers no message, close, or exception handlers and receives no 
messages.
   
   ## Root Cause
   
   `VertxWebsocketEndpoint.getWebSocket(setupCallback)` only invokes the 
`setupCallback` when it opens a **new** connection. When the WebSocket is 
already open (`!webSocket.isClosed()`), the method returns the existing socket 
without calling the callback. Since `VertxWebsocketClientConsumer.connect()` 
passes `this::configureWebSocketHandlers` as the callback, no handlers are 
registered on the pre-existing socket.
   
   ## Fix
   
   - **`VertxWebsocketEndpoint.getWebSocket()`**: added an `else if 
(setupCallback != null)` branch that invokes the callback on the pre-existing 
open socket.
   - **`VertxWebsocketEndpoint.isWebSocketOpen()`**: new package-private helper 
so `VertxWebsocketClientConsumer.connect()` can tell whether the socket was 
pre-existing before calling `getWebSocket()`.
   - **`VertxWebsocketClientConsumer.connect()`**: capture `alreadyOpen` before 
calling `getWebSocket()` and gate the `opened.set(ws)` in the callback on 
`!alreadyOpen`. This preserves the reconnect guard that closes orphaned sockets 
when the consumer is stopped during a reconnect attempt — without it, the guard 
would incorrectly close the shared endpoint WebSocket when the callback fires 
for an already-open socket.
   
   ## Tests
   
   `VertxWebsocketClientConsumerHandlersTest` covers two scenarios:
   
   1. **Stop/restart cycle**: consumer route stopped and restarted while the 
connection is healthy — restarted consumer must receive messages.
   2. **Producer-first**: a producer on the same `consumeAsClient=true` 
endpoint opens the WebSocket; a consumer started afterward must receive 
subsequent messages.
   
   ---
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to