简体   繁体   English

Tomcat WebSocket管理和标识

[英]Tomcat websocket management and identification

I am trying to implement a web socket session manager and I have just encountered a road block that I hope someone can assist me with. 我正在尝试实现Web套接字会话管理器,而我刚遇到一个路障,希望有人可以帮助我。

Basically a client will initiate a web socket session with my websocket server endpoint and I will take the HTTP request parameters, parse it and subscribe to web service producer endpoint. 基本上,客户端将与我的websocket服务器端点发起一个Web套接字会话,我将获取HTTP请求参数,对其进行解析并订阅Web服务生产者端点。 The Web service will return a response containing a subscription identifier of which will use as a key mapping (along with the HTTP session ID) to add to a java map cache with the session object. Web服务将返回一个包含预订标识符的响应,该预订标识符将用作键映射(以及HTTP会话ID),以与会话对象一起添加到Java映射缓存中。 The proceed to send data to my published webservice consumer endpoint. 继续将数据发送到我发布的Web服务使用者端点。 My application will then take the data received from the producer, use the subscription id that comes with each packet and find the right session in the map caches to send the data back to. 然后,我的应用程序将接收从生产者那里收到的数据,使用每个数据包附带的订阅ID,并在地图缓存中找到正确的会话以将数据发送回去。

Here is my problem.. 这是我的问题。

I noticed that if the client opens another tab in the browser and sends a second subscription request, it would still be sent with the same HTTP Session ID yet tomcat will still be able to stream the data to the correct tab. 我注意到,如果客户端在浏览器中打开另一个选项卡并发送第二个订阅请求,则该请求仍将使用相同的HTTP会话ID发送,但是tomcat仍然能够将数据流式传输到正确的选项卡。 This implies that the tomcat websocket implementation has a built in multiplex handling mechanism. 这意味着tomcat Websocket实现具有内置的Multiplex处理机制。

To exclude some unnecessary details unless asked, I want to to also be able identify all the channels that were multiplexed under the same session id. 为了排除一些不必要的细节(除非询问),我还希望能够标识在同一会话ID下多路复用的所有通道。 But I can't find any way in the API to identify it. 但是我在API中找不到任何方法可以识别它。 As I need to be able to look up my map caches and remove sessions for tabs that have been closed (which triggers a close method in my web socket endpoint), but I'm not going to be able to do that as there could be many sockets/channels associated with the same HTTP Session ID. 因为我需要能够查找地图缓存并删除已关闭的选项卡的会话(这会在我的Web套接字端点中触发close方法),但我将无法做到这一点,因为可能与同一HTTP会话ID关联的许多套接字/通道。

The websocket framework does not provide any such implementation. websocket框架不提供任何此类实现。 Every tab opens a new socket. 每个选项卡都会打开一个新的套接字。 You can maintain a session info through adding a key in the request while initiating the websocket and on message check for that key(eg JSESSION id value) in the server and serve the request accordingly. 您可以通过在启动Websocket时在请求中添加密钥来维护会话信息,并在消息中检查服务器中该密钥(例如JSESSION id值)并相应地处理请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM