ZMQ:路由器如何识别经销商 [英] ZMQ : how does a router identify a dealer

查看:36
本文介绍了ZMQ:路由器如何识别经销商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ZMQ 模式经销商/路由器.
在我的项目中,路由器是代理经理,经销商是代理.

I'm using the ZMQ pattern dealer/router.
In my project, a router is an agent manager and a dealer is an agent.

所以我有很多经销商,但只有一台路由器.

So I have many dealers and only one router.

每个经销商都可以向路由器发送自己的请求并等待回复.
路由器侦听一个端口,因此它必须能够识别路由器.

Each dealer can send its own request to the router and wait for the reply.
The router listens to one port so it must be able to identify the routers.

我知道我们可以使用 zmq_setsockopt 为经销商提供一个唯一的 id.如果经销商向路由器发送请求,路由器将收到其唯一 ID 及其请求.

I know that we can use zmq_setsockopt for the dealer to give its an unique id. And if the dealer sends a request to the router, the router will receive its unique id and its request.

假设路由器已经收到来自 10 个经销商的 10 个请求.现在路由器要向第五个经销商发送回复.如何做到这一点?

Imagine that the router has already had 10 requests coming from 10 dealers. Now the router wants to send a reply to the fifth dealer. How to do that?

推荐答案

您所说的内容略有修改...

There's a slight modification to what you've said...

[...] 如果经销商向路由器发送请求,路由器将收到其唯一 ID 及其请求.

[...] if the dealer sends a request to the router, the router will receive its unique id and its request.

(强调)

实际情况是,如果您明确设置身份,经销商会自动选择自己的身份.它仍然会在消息的第一帧中将此标识发送到 ROUTER 套接字,并且您仍然可以使用它向该经销商发送消息,您只需在它进来时跟踪它即可.

The reality is that if you don't explicitly set the identity, the dealer automatically selects its own identity. It will still send this identity to the ROUTER socket in the first frame of the message, and you can still use it to send a message back to that dealer, you just have to keep track of it when it comes in.

您可以阅读更多关于它是如何工作的在指南中.我建议您阅读整篇文章,至少从第 5 章开始,但链接部分涵盖了如何使用 ROUTER 套接字进行通信.

You can read a little more about how this works in the guide. I recommend you read the whole thing, at least from the beginning through chapter 5, but the linked section covers how the communication works with ROUTER sockets.

您没有指定一种语言,但是有许多来自不同语言的示例关于如何使用此这里.

You don't specify a language, but there are many examples from different languages on how to work with this here.

这篇关于ZMQ:路由器如何识别经销商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆