zeromq.js | : zap : Node.js bindings to the ØMQ library | Runtime Evironment library
kandi X-RAY | zeromq.js Summary
kandi X-RAY | zeromq.js Summary
:zap: Node.js bindings to the ØMQ library
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of zeromq.js
zeromq.js Key Features
zeromq.js Examples and Code Snippets
Community Discussions
Trending Discussions on zeromq.js
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 am trying to implement a pub/sub broker with ZeroMQ where it is possible to restrict clients from subscribing to prefixes they are not allowed to subscribe to. I found a tutorial that tries to achieve a similar thing using the ZMQ_XPUB_MANUAL
option. With zeromq.js it is possible to set this option:
ANSWER
Answered 2020-Jul-31 at 16:11In 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 : "Is there a way to call
setSockOpt()
withzeromq.js
or is there another way to accept a subscription?"
So, let me first mention Somdoron to be, out of doubts & for ages, a master of the ZeroMQ tooling.
Next comes the issue. The GitHub-sources, I was able to review atm, seem to me, that permit the ZMQ_XPUB
-Socket-archetypes to process the native API ZMQ_XPUB_MANUAL
settings ( re-dressed into manual
-property, an idiomatic shift ), yet present no method (so far visible for me) to actually permit user to meet the native API explicit protocol of:
ZMQ_XPUB_MANUAL
: change the subscription handling to manual
...
with manual mode subscription requests are not added to the subscription list. To add subscription the user need to callsetsockopt()
withZMQ_SUBSCRIBE
onXPUB
socket.
/__ from ZeroMQ native API v.4.3.2 documentation __/
Trying to blind-call the Socket
-inherited .SetSockOpt()
method may prove me wrong, yet if successfull, it may be a way to inject the { ZMQ_SUBSCRIBE | ZMQ_UNSUBSCRIBE }
subscription-management steps into the XPUB
-instance currently having been switched into the ZMQ_XPUB_MANUAL
-mode.
Please test it, and if it fails to work via this super-class inherited method, the shortest remedy would be to claim that collision/conceptual-shortcommings directly to the zeromq.js
maintainers ( it might be a W.I.P. item, deeper in their actual v6+ refactoring backlog, so my fingers are crossed for either case & my full respect for their brave work ).
QUESTION
The documentation for connect
method says,
Connects to the socket at the given remote address and returns immediately. The connection will be made asynchronously in the background.
But, await
does not seem to be applicable as shown in their example of subscriber code.
subscriber.js
ANSWER
Answered 2020-May-09 at 09:12Q : "what error(s) maybe raised by the
connect()
method?"
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
The ZeroMQ native API distinguishes ( unchanged since v2.1 ) these errors for this :
EINVAL
The endpoint supplied is invalid.
EPROTONOSUPPORT
The requested transport protocol is not supported.
ENOCOMPATPROTO
The requested transport protocol is not compatible with the socket type.
ETERM
The ØMQ context associated with the specified socket was terminated.
ENOTSOCK
The provided socket was invalid.
EMTHREAD
No I/O thread is available to accomplish the task.
Yet your actual observer is dependent on the zeromq.js
re-wrapping these principal states, so the best next step is to re-read the wrapper source code, so as to see, how these native API error states get actually handled inside the zeromq.js
-wrapper.
The remarks :
The following socket events can be generated. This list may be different depending on the ZeroMQ version that is used.
Note that the error event is avoided by design, since this has a special behaviour inNode.js
causing an exception to be thrown if it is unhandled.
Other error names are adjusted to be as close to possible as other networking related event names in Node.js and/or to the correspondingZeroMQ.js
method call. Events (including any errors) that correspond to a specific operation are namespaced with a colon :, e.g.bind:error
orconnect:retry
.
are nevertheless quite warning, aren't they?
Theawait
part
The MCVE-code ( as-is ) is unable to reproduce the live-session, so best adapt the MCVE-code so as to get run-able and we can proceed further on this.
QUESTION
I am doing the example of pubsub
from this link and managed to get it work.
server.js:
...ANSWER
Answered 2020-Apr-02 at 07:39You will want to convert a Buffer to string with toString()
(defaults to utf-8
encoding)
or you can use string-decoder from nodejs
with stringDecoder.write(buffer)
i.e. stringDecoder.write(topic)
QUESTION
Consider a Node.js application with few processes:
- single main process sitting in the memory and working like a web server;
- system user's commands that can be run through CLI and exit when they are done.
I want to implement something like IPC between main and CLI processes, and it seems that ZeroMQ bindings for Node.js is a quite good candidate for doing that. I've chosen 6.0.0-beta.4
version:
Version 6.0.0 (in beta) features a brand new API that solves many fundamental issues and is recommended for new projects.
Using Request/Reply I was able to achieve what I wanted: CLI process notifies the main process about some occurred event (and optionally receives some data as a response) and continues its execution. A problem I have right now is that my CLI process hangs if the main process is off (is not available). The command still has to be executed and exit without notifying the main process if it's unable to establish a connection to a socket.
Here is a simplified code snippet of my CLI running in asynchronous method:
...ANSWER
Answered 2019-Nov-25 at 13:42ZeroMQ decouples the socket connection mechanics from message delivery. As the documentation states connectTimeout
only influences the timeout of the connect()
system call and does not affect the timeouts of sending/receiving messages.
For example:
QUESTION
I'm trying to install ZeroMQ into an electron application but I'm unable to rebuild the package for electron.
I'm trying to install ZeroMQ for electron 5.1.0 on my Windows 10 machine. Details:
OS: Windows 10 Electron: 5.0.8 node: 12.0.0
As per the instructions in the README.md https://github.com/zeromq/zeromq.js/, I have followed this procedure:
1) Install zeromq with npm
npm install zeromq
2) Rebuild for electron
npm rebuild zeromq --runtime=electron --target=5.1.0
Notes: The documentation indicates that the target here is supposed to be the Electron version; however, this causes a 404 error as npm tries to go to https://nodejs.org/dist/v5.0.8/node-v5.0.8-headers.tar.gz which doesn't exist. I then thought to try the node version, but that leads to a 401 error. I then tried the zeromq version (5.1.0 as shown in command) which leads to this error:
error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
Googling this error brings up a lot of StackOverflow problems where the build tools are required. Looking a little ahead on the README.md led me to thing I could solve this problem using the next command.
3) Install visual studio build tools
npm install --global --production windows-build-tools
This command is completed successfully and installs both the build tools and python2.7
4) Rerunning the rebuild command in step 2 leads to the same error. I tried variations of this command:
npm config set msvs_version 2013
using 2015 and 2017 as well.
2013 and 2015 give this error:
error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
gyp ERR! build error
gyp ERR! stack Error: C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\\path\to\app\node_modules\zeromq
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! zeromq@5.1.0 install: node scripts/prebuild-install.js || (node scripts/preinstall.js && node-gyp rebuild)
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the zeromq@5.1.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
While 2017 gives this:
error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 bui
ld tools, please install v140 build tools. Alternatively, you may upgrade to the current Visual Studio tools by select
ing the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\\path\to\app\node_modules\zeromq\build\zmq.vcxproj]
with a similar ending section as the other years produced.
ANSWER
Answered 2019-Aug-13 at 14:38In the end this was a visual studio build tools install error. I uninstalled visual studio using the visual studio installer and then reinstalled windows-build-tools.
QUESTION
To make a long story short, I'd like to run my jest tests (using CLI) with electron instead of node.
It's relevant when using native module, because you need to build them using electron header while jest run them using plain node. So I must either build my native modules for my app (at least in dev mode) or my tests, I can't have both to work.
In this thread they propose to use mocha, but I want to use jest, which is far more advanced and interact well with React. Note that I don't want to mock the native module, since I write integration tests.
I opened an issue about the zmq github repo. One proposed solution is "to target your tests using ELECTRON_RUN_AS_NODE=true electron as your node runtime". This is a very good solution, since using electron will both make the test environment closer to the execution environment and solve my specific issue with native modules.
I'd like to apply that, but I do no seem to be able to setup the jest CLI to use electron instead of node, and I have no idea where to start. Maybe I should run jest programmatically without the CLI ? But I might lose the nice test filtering features of the CLI.
Has anyone solved this already?
...ANSWER
Answered 2018-Mar-07 at 16:07"ELECTRON_RUN_AS_NODE=true ./node_modules/.bin/electron ./node_modules/.bin/jest
works fine
QUESTION
I'm building a HTML page which renders a graph created using VivaGraph ( https://github.com/anvaka/VivaGraphJS ) .
This graph should be fed by data coming from a ZMQ (ZeroMQ) datastream, where my webpage is connected as "Subscriber" to a "Publisher"; the perfect example code is here: https://github.com/zeromq/zeromq.js/#pubsub
The problem is: VivaGraph is for JS on client side while ZMQ is for NodeJS environment.
How can bind my VivaGraph graph to the ZMQ data stream in the client side?
...ANSWER
Answered 2018-Oct-22 at 20:51You could look into libraries like JSMQ or zwssock that implement ZMQ over websockets, however these seem harder to use.
I would go the easy way and place a simple express http server in the middle. Html client sends periodical get requests to the express server, server connects to ZMQ and fetches the data and sends it back to the client as json.
Alternatively, you could also do a websockets connection between the html client and the server, while the server also maintains a connection to ZMQ and pipes data to the websockets.
QUESTION
I have a python program that will accept a ZeroMQ REQ
Requester and provide a number of functionalities, based on the given code.
So if a client sends a code 02
, python will return back a memory statistics, 03
a CPU statistics and so on.
The client is created with nodejs
and zeromq.js
, in order to communicate with the backend. I am not sure what the best way would be to send multiple messages from the frontend, since I will send multiple such messages with different codes each second.
What I have now is something similar to this:
...ANSWER
Answered 2017-Sep-21 at 02:23ZeroMQ uses distributed actors-model for a sort of multi-party behaviour in each of their pre-defined Formal Scalable Communication Archetypes.
The REQ
is just a one part of such multi-party distributed-behaviour.
The opposite and symmetrically cardinal and necessary part is the REP
node.
The complete picture of this distributed-behavioural game ( called REQ/REP
) is this:
REQ
asks,
REP
replies ( yes, first has to receive and indeed read the message & then mus send an answer ),
REQ
can only, after having .recv()
-ed ( un-loaded ) such an answer from REP
, go and ask again the REP
for getting another reply...
This means, your code has to internally get aligned with this and coordinate it's local behaviour so as to meet this distributed-computing behavioural game.
Ignoring these hardwired rules means a problem -- your REQ
-side code n now seems, that it just remains inside its self-locked FSA-state ( wanting to send next messages ), where it simply somehow forgot to also .recv()
the first and subsequent answers, that have ( or will have ) arrived from REP
-side after the REQ
's first .send()
, and thus the REQ
will never be able again ( until the reset, as was explained above ) to .send()
any "next"-message anymore to the REP
-part.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install zeromq.js
Node.js 10.2+ or Electron 3+ (requires a N-API version 3+)
The following platforms have a prebuilt binary available:. If a prebuilt binary is not available for your platform, installing will attempt to start a build from source.
Linux on x86-64/armv7/armv8 with libstdc++.so.6.0.21+ (glibc++ 3.4.21+), for example: Debian 9+ (Stretch or later) Ubuntu 16.04+ (Xenial or later) CentOS 8+
Linux on x86-64 with musl, for example: Alpine 3.3+
MacOS 10.9+ on x86-64
Windows on x86/x86-64
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