对单个端点的多个异步请求的 ZeroMQ 模式

ZeroMQ pattern for multiple asynchronous requests to single endpoint

我正在使用 zmq 开发具有以下网络拓扑结构的分布式应用程序:发起请求的客户端节点和回复请求的服务器节点。由于客户端是一个 node.js 应用程序,我无法在发送调用后阻塞以等待响应,因此情况是客户端可以向同一端点发出多个发送调用。另一方面,服务器是一个移动应用程序,它在一个线程中一次处理一个请求,如果没有任何请求则阻塞。 如果这个配置听起来很奇怪,我正在尝试构建一种由服务器发起的 RPC 到移动设备。

我想使用 DEALER 套接字客户端和 REP 套接字服务器端。来自 zmq 指南关于 DEALER/REP 组合:

This gives us an asynchronous client that can talk to multiple REP servers. If we rewrote the "Hello World" client using DEALER, we'd be able to send off any number of "Hello" requests without waiting for replies.

它可以应用于可以与单个服务器通信的异步客户端吗?这会是一个不错的选择吗?如果不是,我应该使用哪种模式?

Can it be applied to asynchronous client that can talk to one single server? And could it be a good choice?

  1. REQ/REP 不推荐用于通过 Internet 传输的流量。套接字可能会卡在错误状态。
  2. DEALER/REP 用于与 多个 REP 服务器对话的经销商客户端。所以这不适用于您的用例。

If not which pattern should I use?

在我看来,就您而言,使用传统的 DEALER/ROUTER 是可行的方法。我通常做的是在我的消息前添加一个 "tag frame",即包含某种 UUID 的框架,允许我在应用程序级别识别我的请求(及其回复)。