Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.16.0, 2.15.4, 2.17.0
-
None
-
Unknown
Description
Having multiple routes with the same websocket consumer/producer causes only the first route to initialize correctly when the endpoint parameters are different per used consumer/producer endpoint URI.
In the following example only the first route to register the websocket endpoint will work. The second route will not work.
from("websocket://localhost:" + port + "/bar") .transform().simple("The bar has ${body}") .to("websocket://localhost:" + port + "/bar"); from("timer://foo?fixedRate=true&period=12000") .setBody(constant("Broadcasting to Bar")) .to("websocket://localhost:" + port + "/bar?sendToAll=true");
When the endpoint parameters are the same and a header value is used for broadcasting then both routes will work as expected:
from("websocket://localhost:" + port + "/bar") .transform().simple("The bar has ${body}") .to("websocket://localhost:" + port + "/bar"); from("timer://foo?fixedRate=true&period=12000") .setBody(constant("Broadcasting to Bar")) .setHeader(WebsocketConstants.SEND_TO_ALL,constant(true)) .to("websocket://localhost:" + port + "/bar");
The NodeSynchronization / WebSocketStore which contains all registered clients is maintained per endpoint and only the NodeSynchronization of the 1st registered endpoint is linked to the WeboscketServlet. The NodeSynchronization of all subsequent endpoints are not linked to the WebsocketServlet and are unaware of the connected websocket clients.
The endpoints URI /bar and /bar?sendToAll=true are treated as different endpoints, but belong to the same websocket.
I created a fix and will make a PR for it.