zguide | Learning and Using ØMQ
kandi X-RAY | zguide Summary
kandi X-RAY | zguide Summary
ØMQ - The Guide.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Parse lines .
- Apply a transformation to a path .
- Look for a wall
- Move the next token
- Reduce the reduce .
- Loads all objects from the cache .
- Test whether a single part of a single - part message is complete
- Send message to server
- Process a message of a message .
- Send a request to the server
zguide Key Features
zguide Examples and Code Snippets
Community Discussions
Trending Discussions on zguide
QUESTION
I am trying to implement a service using ZeroMQ
and Node.js
.
I am using the ZeroMQ.js bindings for it. The ZeroMQ Guide shows how to process multiple sockets in one thread: using the zmq_poller.
I am trying to implement something similar in Node.js but I can not find a good way how to do this.
I tried using Promise.race() like so:
ANSWER
Answered 2020-Aug-10 at 00:38If you are just trying to read two sockets without any synchronisation then two asyncronous loops that await data may help:
QUESTION
I implemented the lazy pirate pattern for my client module, which works great for retrying the requests. But here's the problem.
- REQ Client sends message to REP server. [OK]
- REP server interprets the message. [OK]
- REP server executes some action, and prepares the response. [OK]
- REP server sends back the response. [OK]
- REQ Clients polls message but doesn't receive any until it timeout. [NOT OK]
- REQ Client restarts the socket, and retries to send the request again. [NOT OK]
- REP Server executes the action again. [THE PROBLEM]
- This time REQ Client successfully receives the response. [OK]
That's the problem, I'm executing the action twice which was intended to be only executed once. I think this is the best way I could explain it.
In certain occasions client can send simultaneously send request to server as I have a coroutine running on a thread, separated from the main thread both of which has functionality that sends request to server. Could this be the cause of it?
I also have multiple of these clients connected to the server, could this be the problem?
Thank you!
...ANSWER
Answered 2020-Aug-09 at 19:56Q1 : "Could this ... coroutine based co-existence ... be the cause of it?"
Yes,
mostly if coroutines use the same instance of the REQ
-archetype.
Q2 : "... could this ... multiple of these clients connected to the server ... be the problem?"
No,
given each client operates on it's own instance of a REQ
-archetype, connected towards the REP
-(server)-side, there ought be no reason to imminent blocks ( for details, read more about the REQ/REP
principal certainty to fall into an un-salvagable mutual dead-lock, where the only thing you cannot know is, when it will happen, but we all may be sure, it will happen )
If an atomic, singleton-alike unique executions are needed ( and if server implementation permits that ), one may log each REQ
's task-{UUID}
, to prevent double-shots onto the same task-target.
There is hardly to tell more, without the actual MCVE / MWE-representation of the problem ( the .poll
-ing loop logic / timeout / remedy-strategies )
In case one has never worked with ZeroMQ,
one may here enjoy to first look at "ZeroMQ: Principles in less than Five Seconds"
before diving into further details
QUESTION
I am trying to adopt the ZeroMQ asynchronous client-server pattern described here with python multiprocessing. A brief description in the ZeroMQ guide
It's a DEALER/ROUTER
for the client to server frontend communication and DEALER/DEALER
for the server backend to the server workers communication. The server frontend and backend are connected using a zmq.proxy()
-instance.
Instead of using threads, I want to use multiprocessing
on the server. But requests from the client do not reach the server workers. However, they do reach the server frontend. And also the backend. But the backend is not able to connect to the server workers.
How do we generally debug these issues in pyzmq
?
How to turn on verbose logging for the sockets?
The python code snippets I am using -
server.py
...ANSWER
Answered 2020-Jun-30 at 00:14Q : "How to turn on verbose logging for the sockets?"
Start using the published native API socket_monitor()
for all relevant details, reported as events arriving from socket-(instance)-under-monitoring.
Q : "How do we generally debug these issues in
pyzmq
?"
There is no general strategy on doing this. Having gone into a domain of a distributed-computing, you will almost always create your own, project-specific, tools for "collecting" & "viewing/interpreting" a time-ordered flow of (principally) distributed-events.
Last but not least :avoid trying to share a
Context()
-instance,the less "among" 8 processes
The Art of Zen of Zero strongly advocates to avoid any shape and form of sharing. Here, the one and the very same Context()
-instance is referenced ("shared") via a multiprocessing.Process
's process-instantiation call-signature interface, which does not make the inter-process-"sharing" work.
One may let each spawned process-instance create it's own Context()
-instance and use it from inside its private space during its own life-cycle.
Btw. your code ignores any return-codes, documented in the native API, that help you handle ( in worse cases debug post-mortem ) what goes alongside the distributed-computing. The try: ... except: ... finally:
scaffolding also helps a lot here.
Anyway, the sooner you will learn to stop using the blocking-forms of the { .send() | .recv() | .poll() }
-methods, the better your code starts to re-use the actual powers of the ZeroMQ.
In case one has never worked with ZeroMQ,
one may here enjoy to first look at "ZeroMQ: Principles in less than Five Seconds"
before diving into further details
QUESTION
The following in translated from the Divide and Conquer example in the ZeroMQ guide.
...ANSWER
Answered 2020-May-11 at 15:43open System
open System.IO
open System.Threading
open System.Threading.Tasks
open NetMQ
open NetMQ.Sockets
let parallel_task () =
let task_number = 100
let uri_source, uri_sink =
let uri = "ipc://parallel_task"
Path.Join(uri,"source"), Path.Join(uri,"sink")
let ventilator () =
let rnd = Random()
use source = new PushSocket()
source.Bind(uri_source)
use sink = new PushSocket()
sink.Connect(uri_sink)
let tasks = Array.init task_number (fun _ -> rnd.Next 100+1)
printf "Press enter when workers are ready.\n"
printf "Total expected time: %A\n" (TimeSpan.FromMilliseconds(Array.sum tasks |> float))
Console.ReadLine() |> ignore
sink.SendFrame("0")
printf "Sending tasks to workers.\n"
Array.iter (string >> source.SendFrame) tasks
Thread.Sleep(1)
let worker i () =
printf "Starting worker %i\n" i
use source = new PullSocket()
source.Connect(uri_source)
use sink = new PushSocket()
sink.Connect(uri_sink)
while true do
let msg = source.ReceiveFrameString()
printf "Worker %i received message.\n" i
Thread.Sleep(int msg)
sink.SendFrame("")
let sink () =
use sink = new PullSocket()
sink.Bind(uri_sink)
let watch = Diagnostics.Stopwatch()
for i=1 to task_number do
let _ = sink.ReceiveFrameString()
if watch.IsRunning = false then watch.Start()
printf (if i % 10 = 0 then ":" else ".")
printf "\nTotal elapsed time: %A msec\n" watch.Elapsed
Task.Run ventilator |> ignore
for i=1 to 4 do Task.Run (worker i) |> ignore
Task.Run(sink).Wait()
QUESTION
I came across this document http://zguide.zeromq.org/page:all but couldn't find anything regarding totally ordered multicast. How does ZeroMQ order its messages?
...ANSWER
Answered 2020-Mar-20 at 12:15In case one has never worked with ZeroMQ,
one may here enjoy to first look at "ZeroMQ Principles in less than Five Seconds"
before diving into further details
Q : "How does ZeroMQ order its messages?"
Welcome to the lands of Zen-of-Zero. ZeroMQ has been designed so as to be ultra-fast, exceptionally smart and not to do a single step beyond what is necessary.
This said, there is, since ever ( and seems to be still un-damaged & valid in 2020/Q2 ), Zero-Warranty for a message to be delivered - i.e. in a symmetrically reflected point of view, users receive a Warranty that any message, that was delivered is a binary copy of the originator-side message payload pull stop. No other warranties ( i.e. the very same is thus valid for any (re)-order-ing ).
QUESTION
I'm reading the ZeroMQ Guide and came across the following passage in regards to the ROUTER
socket and identities:
An application that uses a
ROUTER
socket to talk to specific peers can convert a logical address to an identity if it has built the necessary hash table. BecauseROUTER
sockets only announce the identity of a connection (to a specific peer) when that peer sends a message, you can only really reply to a message, not spontaneously talk to a peer.This is true even if you flip the rules and make the
ROUTER
connect to the peer rather than wait for the peer to connect to theROUTER
. However you can force theROUTER
socket to use a logical address in place of its identity. Thezmq_setsockopt
reference page calls this setting the socket identity.
According to this passage, "you can only really reply to a message, not spontaneously talk to a peer", meaning a ROUTER
can't send a message to a specific DEALER
, but the next sentence implied that you can if you force the router socket to use a logical address: "However you can force the ROUTER
socket to use a logical address in place of its identity". This part confuses me because they just said that you cant spontaneously send messages from a router to a dealer, but now they claim you can. If you follow this link to the guide, you'll see that after this passage, they say "It works as follows", but the steps they give don't seem to clear up how to send a spontaneous message from a ROUTER
to a specific DEALER
and return a response back to the original ROUTER
.
My question: Is it possible for a single ROUTER
socket to send a request to a specific DEALER
(Out of many) socket and the DEALER
send the result of the request back to the ROUTER
? And if it is possible, how can this be done?
Follow up question: If this is not possible, is there a better combination of sockets to approach this?
Below is a crude diagram of my intended design:
Basically, the client send a request to 1 specific server, that server processes the request and returns the result of the request to the client. The client now has that result, and it knows what server it was processed on.
...ANSWER
Answered 2020-Feb-26 at 16:10Q : Is it possible for a single
ROUTER
socket to send a request to a specificDEALER
(Out of many) socket and theDEALER
send the result of the request back to theROUTER
? And if it is possible, how can this be done?
No, this is to the best of my knowledge not possible - it tries a DEALER/ROUTER
anti-pattern.
Q : is there a better combination of sockets to approach this?
Yes, this could be possible in a bit wild approach to manually-driven identity-frames in ROUTER/ROUTER
.
In case one has never worked with ZeroMQ,
one may here enjoy to first look at "ZeroMQ Principles in less than Five Seconds"
before diving into further details
While one can tweak the ROUTER
-side with identity tricks, your problem fails at the DEALER
-side, where a fair-queue and round-robin policies destroy your wished-to-have 1:1-relation and the pairing of the JobREQ:ResultREP
will fail.
ZeroMQ archetypes are smart and multi-layered inside, beyond of what you typically work with when calling any of the API methods. Some insight into (simplified, maybe oversimplified) inner work might help in this :
QUESTION
I've put together this minimal example in order to send a message from a Router socket to a specific DEALER socker (That has it's identity set). When running these two programs it appears to hang on the ROUTER waiting from the reply from the DEALER, and the DEALER hangs waiting for the request from the ROUTER. So it appears that the message that the ROUTER is sending is never making it to the DEALER.
Router.cpp
...ANSWER
Answered 2020-Feb-24 at 23:35The main idea about ROUTER/DEALER pattern is that it is an asynchronous generalisation of REPLY/REQUEST. Yet you are trying to reverse the sockets in your pattern, discovering it doesn't fit and contorting the code to try and make it fit. Don't do that.
What you need to do is "go with the flow". In the simple method, for which examples exist, the DEALER should send the first message. The ROUTER then responds to that.
The next level is for the DEALER to identify itself in its startup message. The ROUTER can then give a specific response to that DEALER.
At the next level you can go truly asynchronous. The ROUTER can take a copy of each DEALER's identification message, and use the message copies to send asynchronous messages to any DEALER at any time. One copy of the identification message would have the "PEER2" frame appended to it and sent to the DEALER. This works because the copies of the messages include the routing frames. Ideally, you would also strip the 'message' frames, to leave only the routing frames in the copy.
Caveat - I don't use cppzmq, I use CZMQ. I can say that using CZMQ this sort of frame manipulation is very easy.
QUESTION
Is it possible for a publisher to publish to multiple clients on the same machine using ZeroMQ? I'd like a set of clients, each of which can make standard Request/Response calls using SocketType.REQ and SocketType.REP, but which can also receive notifications using SocketType.SUB and SocketType.PUB.
I've tried to implement this topology, taken from here, although my version only has one publisher.
Here is my publisher:
...ANSWER
Answered 2020-Feb-06 at 17:28Q : Is it possible for a publisher to publish to multiple clients on the same machine using ZeroMQ?
Oh sure, it is. No doubts about that.
Check the code. The responsibility of the order-of-execution is there. In distributed-systems this always so.
Once the [Client]-No1
instance gets a plausible .readLine()
-ed input
it will jump-in:
QUESTION
I'm writing an electron app in which I'd like to receive a video (webcam video) sent from python backend via ZeroMQ PUB/SUB patter. I have a properly working server in python which I tested with a python client-receiver.
My python video publisher
...ANSWER
Answered 2020-Jan-03 at 14:26The problem was with sending the topic in the message. NodeJS wrapper didn't see the topic when it was send as a string with only a blank whitespace separating the topic and the payload. To properly send the message topic I had to use a send_multipart function.
QUESTION
I have two OpenWrt (18.06.4) VM's (A and B) in VirtualBox and I'm trying to send messages in a publisher-subscriber scheme using ZeroMQ. A is the server, B is the client.
I'm using the following code:
Publisher code: http://zguide.zeromq.org/c:psenvpub
Subscriber code: http://zguide.zeromq.org/c:psenvsub
and it works on my computer, so I decided to try it on the VMs.
I had to compile both (using the SDK) so I can execute them in the VMs. I compiled two times, changing one minor detail:
1) client listening to the IP 10.0.1.4 of the server
2) client listening to the IP 192.168.56.10 of the server
Both versions were tested in the VMs and in both, the server sends the messages (the send function executes and prints the message sent) but the client never receives any message (message is always null).
About my network configuration. In VirtualBox, I have a Nat Network (10.0.1.0/24) and a virtualbox network (192.168.56.1/24). Both VM A and B have a host-only adapter (vboxnet0) and a NAT network adapter. The machines can ping each other.
The network configuration of the machines is the following:
A
...ANSWER
Answered 2019-Sep-30 at 04:31Avoid the dependency on symbolic-address resolution:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install zguide
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page