简体   繁体   English

净值申请-多个请求响应

[英]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. 我想我可以在Netty中做到这一点,因为它以Java网络框架选项而闻名。

I have devices that are connected to Netty server (TCP via GPRS). 我有连接到Netty服务器(通过GPRS的TCP)的设备。 Suppose that they are all connected permanently (keepalive) and there are several cases which I need to cover with this architecture: 假设它们全部永久连接(keepalive),并且在这种情况下需要涉及几种情况:

Case 1 : Device can send message to the Netty and Netty responses to that message 情况1 :设备可以向Netty发送消息,并且Netty对该消息进行响应

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 情况2 :设备可以向Netty发送消息并向该消息发送Netty响应,但是Netty应该立即向该设备发送多条消息,但是对于每条消息,它必须等待响应后才能发送下一条消息

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 情况3 :应用程序中发生了某些事件(Netty范围外),Netty应该对该事件做出反应并将消息发送到特定设备并从中获取响应

Questions: 问题:

Case 1 : It's clear 情况1 :很明显

Case 2 : How can I develop such case when you actually have synchronized requests and Netty is asynchronous framework? 情况2 :当您实际上有同步的请求并且Netty是异步框架时,如何开发这种情况?

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? 情况3 :是否可以进入Netty上下文并获得特定设备的特定连接(线程)并将消息发送到该设备?

Case 2 情况二

You can add a listener to your write and have that trigger the next write. 您可以在您的写入中添加一个侦听器,并触发下一次写入。

Case 3 情况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. 如果您知道哪个ChannelHandlerContext属于您感兴趣的设备(可以通过在每次建立连接时在Map中注册这些设备来存储它们),则可以使用该上下文触发事件。 Netty will take care of queueing up that event and making sure it processes in the proper thread and channel. Netty将负责排队处理该事件,并确保其在适当的线程和通道中进行处理。

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

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