是否可以添加事件处理ZeroMQ来处理数据收到/发送? [英] Is it possible to add an event handling to ZeroMQ to act when data is received/sent?

查看:279
本文介绍了是否可以添加事件处理ZeroMQ来处理数据收到/发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux Ubuntu中已经在C中创建了两个不相关的守护进程。这些进程处于睡眠模式,它们只在接收到数据时才醒来,并且执行信号处理程序中执行的操作并再次进入休眠状态。



我已经使用SIGNAL IPC和消息队列实现了这种通信。在发送消息之前,我发送信号 SIGUSR1 然后发送数据,我写了 SIGUSR1 的信号处理程序执行所需的操作。



我想使用ZeroMQ实现相同的通信方式,我一直在阅读他们的指南来了解,当数据到达时(C语言),ZeroMQ是否有其他进程的任何类型的事件处理或通知方法。



我也引用了以下链接: / p>

当数据到达时,ZeroMQ是否有通知/回拨事件/消息?



但我仍然怀疑。 >

ZeroMQ通知或触发其他进程一些事件,当一个新的数据被发送(我不想等待或 poll()直到数据到达,而不是d aemon进程将睡眠,数据到达时,它将执行其处理程序并再次睡眠)?



如果有人可以帮助/建议,这将是很好的。 / p>

解决方案

否。



在原状态下,ZeroMQ不实现触发器和回调。



为什么?



由于核心消息传递的心态是使用队列,不要打扰进程的流程,除非进程本身发现可以请求队列(无论是使用智能方式,通过 .poll()进行测试,或者一个愚蠢的方式,直接调用 .recv(ZMQ_NOBLOCK)),如果有任何消息准备好并等待他们的后期处理,然后将开始来自ZeroMQ侧的线程及其资源&()的 .recv() 处理他们自己的过程的脚印和工作流程。






但POSIX SIGNAL -s力学改变游戏规则:



鉴于ZeroMQ本身的事实, SIGUSR1 可以向接收过程提供一个独立的(简单的上下文对齐)带外信号,过程刚刚封锁了一些要处理,发送和传送的通信,因此接收过程可以激活并遵循工具&尽管事实上ZeroMQ技术不能自行提供回调方法,但是从零MQ传递路径的 .recv()的数据方法。 / p>

所以在这个意义上,即使是算法的命令式语言实现也​​成为上一个ZeroMQ调用成功/失败的上下文使用,O / S POSIX信令层(完全独立于分布式ZeroMQ消息传递/信令传递基础设施)可以提供这种寻求的进程间协调手段,旨在在待测进程网络的即时睡眠/守护进程之间工作。


I have created two unrelated daemon processes in C in Linux Ubuntu. These processes are in the sleeping mode, they only wake up when the data is received, and perform the action implemented in the signal handler and again sleep.

I have implemented this communication using SIGNAL IPC and message queue. Before sending the message, I send the signal SIGUSR1 and then send the data, and I wrote the signal handler for SIGUSR1 to perform required action.

I would like to implement the same way of communication using ZeroMQ and I have been reading their guide to find out, whether ZeroMQ has any kind of event handling or notification method for other process, when the data has arrived ( for C language ).

I have referred the following link too:

Does ZeroMQ have a notification/callback event/message for when data arrives?

But still I am doubtful.

Does ZeroMQ notify or trigger other process some event, when a new data has been sent ( I do not want to wait or poll() until the data arrives, instead my daemon process would be sleeping and when the data arrives, it would execute its handler and sleep again )?

It would be great if someone can help / suggest on this.

解决方案

No.

In as-is state, ZeroMQ does not implement either a trigger nor a callback.

Why?

Because the core Messaging mindset is to use Queues, not to disturb the flow of the processes, unless the processes themselves find it feasible to ask the Queue ( be it using a smart way, testing via .poll(), or in a dumb way, by a straight call to .recv( ZMQ_NOBLOCK ) ), if there are any messages ready and waiting for their post-processing and will then start to .recv() them from the ZeroMQ-side thread(s) and its resources & process them on their own process' footprint and work-flow.


But POSIX SIGNAL-s mechanics change The Rules of the Game:

Given the facts about the ZeroMQ per-se, the SIGUSR1 can deliver an independent ( just context-of-use aligned ) "Out-of-Band" signal to the receiving-process, that the sender-process has just marshaled some communication to be processed, sent and delivered down the road, so the receiving process may activate and follow the tools & methods for .recv()-ing data from the ZeroMQ delivery-path, in spite of the fact, that ZeroMQ mechanics does not provide call-back methods on its own.

So in this sense, that even the imperative language implementation of the algorithm becomes context-of-use aware about the success / failure of the last ZeroMQ call, the O/S POSIX signalling layer ( fully independent of the distributed ZeroMQ messaging / signalling delivery infrastructure ) can provide such sought means of inter-process coordination aimed at working among even sleeping / daemon instances of process-networks under test.

这篇关于是否可以添加事件处理ZeroMQ来处理数据收到/发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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