简体   繁体   中英

Netty application - multiple request response

I am trying to make architecture of the application in a clean way. I suppose that I can do that in Netty since it is famous as a java networking framework option.

I have devices that are connected to Netty server (TCP via GPRS). Suppose that they are all connected permanently (keepalive) and there are several cases which I need to cover with this architecture:

Case 1 : Device can send message to the Netty and Netty responses to that message

Case 2 : Device can send message to the Netty and Netty responses to that message, but immediately Netty should send multiple messages to the device but for each message it must wait for response before send the next one

Case 3 : Some event occurs in the application (outside Netty scope), Netty should react to that event and send message to the specific device and get response from it

Questions:

Case 1 : It's clear

Case 2 : How can I develop such case when you actually have synchronized requests and Netty is asynchronous framework?

Case 3 : Is it possible to get into Netty context and get particular connection (thread) of the specific device and send message to that device?

Case 2

You can add a listener to your write and have that trigger the next write.

Case 3

If you know which ChannelHandlerContext belongs to the device you are interested in (which you could store by registering these in a Map as each connection is made), then you can fire events using that context. Netty will take care of queueing up that event and making sure it processes in the proper thread and channel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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