- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 C++ 程序,该程序需要能够从任意数量的其他客户端发送/接收 JSON
-payload。
起初,我尝试实现 PubNub 服务,但我发现我无法同时获取和发布消息(即使在不同的线程上使用两个不同的上下文)。我需要能够做到这一点。我还发现 PubNub 的延迟太长,我不喜欢。
我遇到了 ZeroMQ具有满足我需要的 PUB/SUB
模型的库。但是所有examples我无意间解释了如何以一个进程是发布者或订阅者的方式来实现它,而不是同时两者。
理想情况下,我想编写一个服务器,将来自任何人的所有消息转发给订阅消息中指定的特定 channel 的任何人。 任何人都应该能够接收消息并向网络上的任何其他人发布消息,前提是他们订阅了正确的 channel 。
UPDATE 1:
注意:我不需要接收保险,因为有效载荷 N+1 将优先于有效载荷 N。我想要一个发送后忘记的通信方式(类似 UDP)。
根据要求:PubNub 限制 32 kB
每个 JSON
-payload 对我来说是完美的,我不需要更多。事实上,我的有效载荷平均约为 4 kB
。所有客户端实例都将在同一个本地网络上运行,因此理想情况下,延迟应小于 5 毫秒
。至于客户端数量,一次不会超过 4 个客户端订阅同一个 channel /主题。
UPDATE 2 :
我无法提前预测会有多少个 channel /主题,但大约有几十个(大部分时间)、数百个(高峰期)。不是几千。
问题 1:
- 我可以使用 ZeroMQ
实现这样的行为吗?Q2:
- 是否有任何工作示例可以证明这一点(最好是 C++
)?Q3:
- 如果没有,对 C++
中的库有什么建议吗?
最佳答案
ZeroMQ :
is capable of serving this task well within scales given above
nanomsg :
is capable of serving this task too, a need to cross-check ports/bindings for clientsDesign review:
PUB
的内容-作为消息负载SUB
的内容-scribe 作为实际传入的消息流 TOPIC
-过滤器JSON
- 它准备/制作的格式化消息JSON
-格式化的形状,并且在接收完成后将尝试对其进行本地处理JSON
的最大尺寸-格式化的payload小于 32 kB
,关于 4 kB
平均5,000 [usec]
URL
-所有迟到者的目标.connect()
-sProposal:
server may deploy multiple behaviours to meet the given goals, using both thePUB
andSUB
behaviours, and provides a code-driven, fast,SUB
-side attached, non-blocking event-loop.poll()
with aligned re-transmission of any of it'sSUB
-side.recv()
-ed payloads to it'sPUB
-side, currently.connect()
-ed, audience ( live client instances ):
sets_SUB_recv = aZmqCONTEXT.socket( zmq.SUB );
ands_PUB_send = aZmqCONTEXT.socket( zmq.PUB );
for performance reasons, that are not so tough here, one may also segregate workload-streams' processing by mapping each one on disjunct sub-sets of the multiple created I/O-threads:
maps_SUB_recv.setsockopt( ZMQ_AFFINITY, 0 );
ands_PUB_send.setsockopt( ZMQ_AFFINITY, 1 );
sets_PUB_send.bind( "tcp://localhost:8899" );
+
sets_SUB_recv.setsockopt( ZMQ_SUBSCRIBE, "" ); // forever *every*-TOPIC
sets_SUB_recv.setsockopt( ZMQ_MAXMSGSIZE, 32000 ); // protective ceiling
sets_SUB_recv.setsockopt( ZMQ_CONFLATE, True ); // retain just the last msg
sets_SUB_recv.setsockopt( ZMQ_LINGER, 0 ); // avoid blocking
sets_SUB_recv.setsockopt( ZMQ_TOS, anAppToS_NETWORK_PRIO_CODE );
ands_SUB_recv.bind( "tcp://localhost:8888" ); // [PUB]s .connect()
Similarly,
client instance may deploy a reverse-facing tandem of both aPUB
-endpoint andSUB
-endpoint, ready to.connect()
to a known transport-target-URL
.
The client specific subscription locally decides, what is to get filtered from the incoming stream of messages ( prior toZeroMQ v.3.1 API
the plentitude of all messages will get delivered to each client instance over the transport class, however sinceAPI v.3.1+
, the topic-filter is being operated on thePUB
-side, which in the desired modus-operandi eliminates the wasted volumes of data over the network, but at the same time, this increases thePUB
-side processing overhead ( ref.: remarks on a principle of increased multi-I/O-threads mapping / performance boost above )
setc_SUB_recv = aZmqCONTEXT.socket( zmq.SUB );
andc_PUB_send = aZmqCONTEXT.socket( zmq.PUB );
unless the payload-assembly/processing overhead grows close to the permitted End-to-End latency threshold, there shall be no need to separate / segregate theZeroMQ
low-level I/O-threads here:
mapc_SUB_recv.setsockopt( ZMQ_AFFINITY, 0 );
andc_PUB_send.setsockopt( ZMQ_AFFINITY, 1 );
setc_PUB_send.connect( "tcp://server:8888" ); // reverse .bind on [SUB]
+
setc_SUB_recv.setsockopt( ZMQ_SUBSCRIBE, "" ); // modified on-the-fly
setc_SUB_recv.setsockopt( ZMQ_MAXMSGSIZE, 32000 ); // protective ceiling
setc_SUB_recv.setsockopt( ZMQ_CONFLATE, True ); // take just last
setc_SUB_recv.setsockopt( ZMQ_LINGER, 0 ); // avoid blocking
setc_SUB_recv.setsockopt( ZMQ_TOS, anAppToS_NETWORK_PRIO_CODE );
andc_SUB_recv.connect( "tcp://server:8899" );
对于业余项目,消息基础设施不需要太多,然而对于更严肃的领域,服务器和客户端实例应该有额外的服务添加了一些进一步的正式交流模式行为。
- r/KBD
用于远程键盘,带有 CLI
-类似的临时检查工具
- KEEP_ALIVE
允许全系统状态/性能监控的转发器
- SIG_EXIT
允许系统范围/实例特定的处理程序 SIG_EXIT
- distributed syslog
服务允许安全地收集/存储日志记录的非阻塞拷贝(无论是在调试阶段还是性能-tuninc 阶段或生产级证据记录收集)
- Identity Management
审计追踪等工具
- WhiteList/BlackList
为基础设施增加稳健性,使其更好地抵抗 DoS 攻击/中毒、错误的 NIC 流量突发等
- Adaptive Node re-Discovery
用于更智能/临时基础设施设计和状态监控,或当多角色/( N + M )-shaded active hot-standby 角色切换/接管场景等出现时
A1
: 是的,完全在 ZeroMQ 能力范围内
A2
:是的,ZeroMQ 书籍/指南中的 C++ 代码示例可用
A3
: Ref.: A1, plus may like indepth remark in Martin SUSTRIK's post on "Differences between nanomsg
and ZeroMQ
"
希望您能享受分布式处理的力量,ZeroMQ
支持它或 nanomsg
或两者兼而有之。
只有自己的想象力才是极限。
如有兴趣further details, one might love the book referred to in the The Best Next Step section of this post
关于c++ - ZeroMQ 并发发布和订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37265557/
你能举一些zeromq的例子吗? 最佳答案 假设您想要某种公告板。您希望通过订阅公告板来只允许某些人看到它。 这可以使用 ZeroMQ 的发布者/订阅者模型来完成。 现在,假设您需要发送一些异步消息。
因此,正如我在上一篇文章中所问的那样,我希望能够使用不同语言编写的程序或函数在它们之间进行通信。 我最近遇到了 zeromq,我试图弄清楚这是否可以帮助我,因为它提供了某种套接字。例如,zeromq
与通过 POLLIN 多路复用多个套接字有何不同? while True: socks = dict(poller.poll()) if socks.get(control_recei
我正在设计一个与 ZeroMQ 对话的服务器应用程序。无需深入细节,服务器将存储和服务(来自查询请求)(eventid, eventstring)元组。 我的问题涉及有线协议(protocol)的设计
我有一个服务器(在 Amazon 上运行)和一个连接到它的客户端。建立连接后,客户端和服务器专门相互通信并发送消息。 例如 1. Client -> Server 2. Client -> Serve
我正在开发一个新的客户端-服务器应用程序 (.Net),并且到目前为止一直在使用 WCF,它非常适合应用程序的请求-响应方法。然而,我被要求用基于套接字的解决方案替换它,部分是为了支持非 .Net 客
我正在尝试做一个发布/订阅架构,其中多个发布者和多个订阅者存在于同一总线上。根据我在互联网上阅读的内容,只有一个套接字应该调用 bind(),而所有其他套接字(无论是 pub 还是 sub)都应该调用
使用zeromq,发送者发送10条消息后,发送者崩溃。 场景1:接收方正在一条一条地处理消息,花费了一些明显的时间成本,在这种情况下它还会收到 10 条消息吗? 场景 2:另一种情况是,当接收器崩溃时
我有一个 ZeroMQ 套接字,它正在从不同机器上的多个进程接收数据。在不改变数据内容的情况下,有没有办法识别数据的来源呢?具体来说,我想要发送者的 IP 地址(如果它来自 TCP 连接)。 最佳答案
有人知道在哪里可以找到有关 ZeroMQ 延迟与 29 West LBM 等竞争对手的性能详细信息吗? 看起来便宜得多,但我找不到任何指标来决定哪个更合适。 最佳答案 ZeroMQ 和 29West
有没有办法在不使用转发器概念的情况下使用 zeroMQ 库进行消息广播? 最佳答案 是的,一个 PUB 套接字将广播到所有连接的 SUB 套接字。只有当您想要桥接不同的网络时才需要转发器(代理),例如
几天前我才开始使用zeromq。我的目标是设计一个具有多个代理(代理网络)的发布订阅系统。我已经阅读了 zeromq 指南的相关部分,并为简单的发布子系统编写了代码。如果有人可以帮助我解决以下问题:
我需要编写一个订单管理器,将客户(股票、外汇等)订单发送到适当的交易所。客户想要发送订单,但对 FIX 或其他专有协议(protocol)一无所知,只知道发送订单的内部(规范化)格式。我有应用程序(服
我正在尝试从示例 wuclient/wuserver 在 zeromq 上实现一个惰性订阅者。 客户端比服务器慢得多,因此它必须只获取服务器最后发送的消息。 到目前为止,我发现这样做的唯一方法是连接/
我是 ZeroMQ 的新手并试图找出设计问题。我的情况是我有一个或多个客户端向单个服务器发送请求。服务器将处理请求,做一些事情,并向客户端发送回复。有两个条件: 回复必须发送到发送请求的客户端。 如果
如 docs 中所述在 3.x 版本的 zeromq 中,PUB/SUB 场景中的消息正在被过滤 出版商侧(而不是在订阅者方面,这是微不足道的)。 对我来说,这听起来像是发布者必须持有所有连接的套接字
引自 ZeroMQ 指南 However, with a little extra work, this humble pattern becomes a good basis for real wo
假设我有一个带有 ZeroMQ 接口(interface)的节点(进程、线程等),比方说一个 REP 套接字。这意味着我有一个无限主循环,它在 zmq_recv 或 zmq_poll 函数中休眠。 现
我想以某种方式比较 grpc 与 Zeromq 及其模式的功能:并且我想创建一些比较(功能集) - 不知何故 - 0mq 是“更好”的套接字 - 但无论如何 - 如果我应用 0mq模式 - 我认为我得
我正在试验 ZeroMQ。我发现在 ZeroMQ 中非常有趣,connect 或 bind 先发生并不重要。我试着查看 ZeroMQ 的源代码,但它太大了,找不到任何东西。 代码如下。 # clien
我是一名优秀的程序员,十分优秀!