Open Spandana806 opened 11 months ago
WebSocket proxying is possible, but not implemented -- this is one of the first times we get asked about this.
We have implemented it as a proof-of-concept (not production ready code) in a test case here: https://github.com/jetty/jetty.project/blob/jetty-10.0.18/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/proxy/WebSocketProxy.java
If you want to write your own you can start from there.
Alternatively, you may establish a commercial support from Webtide, and we will write the code for you and for the whole community -- a great way to give back.
Hi Simone, Thank you for the prompt response. As per the document, there are two ways of implementing websockets, I have tried the first way of using standard javax.websocket API. I have added a websocket server which opens a new client session to my target server and thus acting as a proxy between actual client and the target server.
Below is the pictorial representation of how I achieved websocket proxying using javax APIs:
Please confirm if it is the right way to achieve websocket proxying.
I will be trying your suggestion which uses Jetty-specific WebSocket APIs. Is there any difference in terms of performance or in any other way, between the standard javax APIs and the jetty specific APIs?
I recommend you do it with the Jetty 12 WebSocket APIs because they have better support for backpressure: https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-server-websocket-jetty
The problem with the Jakarta APIs is that you have to block if a remote peer is slow, and this could cause scalability issues.
With the Jetty WebSocket APIs you have full control on asynchronous writes and on the demand for more WebSocket frames.
Thank you, I will try with Jetty12 APIs.
11.0.17
Question Does Jetty support websocket proxying? I want my application to be able to proxy http requests and websocket requests via Jetty server.
Using ProxyServlet.Transparent, I am able to redirect my http requests to target server and get responses. How do we achieve the same redirection for websocket subscriptions?
The below implementation works:
Code snippet:
How do we achieve the reverse proxying for websocket subscriptions?