netty websocket + continuous PERIODIC data push
-
12-06-2021 - |
質問
What would be the best way to continuously push some data periodically(say every n seconds) from a websocket server in netty?
EDIT :
I came across this post : Best way to send continuous data in Java using Netty and according to the answer,while/sleep wouldnt be very scalable, how does one schedule a job on an Executor ?
解決
- WebSocket client connects to your Netty server, handshakes and establishes a websocket connection.
- The server registers the client's channel somewhere where it can be retrieved when there's data to send. (I use a ChannelGroup in a singleton)
- The scheduled job fires, gets some data from somewhere, then gets a reference to the client's channel and writes the data to it.
- The client channel's pipeline should have a few encoders in it that marshal the scheduled job supplied data into websocket frames.
所属していません StackOverflow