Follow the instructions below to download and install the selected ZeroMQ
library.
OSX
You need Brew installed and configured https://brew.sh/
czmq and zyre are also available.
Linux
Fedora
Ubuntu/Debian/Mint
apt-get install libzmq3-dev
Arch
SUSE
zypper install zeromq-devel
Packages for Debian, Ubuntu, Fedora, CentOS, RHEL, SUSE
The ZeroMQ maintainers provide pre-built binary packages for libzmq, czmq, zyre, malamute, zproject and zproto, automatically built from both the latest stable releases OR the latest commit in the Git repositories via the Open Build Service for i386, amd64, armv7, arm64, ppc64, s390x (note: depends on the distribution).
- latest git, no DRAFT APIs
- latest git, with DRAFT APIs
- latest stable release, no DRAFT APIs
- latest stable release, with DRAFT APIs
Add the repository of your choice by clicking on the distribution and version, and then follow “Go to download repository”. That is the URL of the repository. Remember to add the GPG key.
For example, to add Debian 9 and install the development packages for libzmq from the latest stable release without draft APIs:
echo "deb http://download.opensuse.org/repositories/network:/messaging:/zeromq:/release-stable/Debian_9.0/ ./" >> /etc/apt/sources.list
wget https://download.opensuse.org/repositories/network:/messaging:/zeromq:/release-stable/Debian_9.0/Release.key -O- | sudo apt-key add
apt-get install libzmq3-dev
Install from a package manager
Linux
Deb packages are available for Debian and Ubuntu.
For other distros please refer to pkgs.org.
You can also get prebuild binaries for latest git master
for most distros on openSUSE’s Build Service:
Git master
only stable APIs: http://software.opensuse.org/download.html?project=network%3Amessaging%3Azeromq%3Agit-stable&package=czmq
Git master
including draft APIs: http://software.opensuse.org/download.html?project=network%3Amessaging%3Azeromq%3Agit-draft&package=czmq
MacOS
On macOS install czmq with Homebrew see here.
Windows
Using vcpkg
If you are already using vcpkg, you can download and install czmq
with one single command:
vcpkg.exe install czmq
this will build czmq
as a 32-bit shared library.
vcpkg.exe install czmq:x64-windows-static
this will build czmq
as a 64-bit static library.
You may also build czmq
with one or more optional libraries:
vcpkg.exe install czmq[curl,httpd,lz4]:x64-windows
this will build czmq
with libcurl
, libmicrohttpd
, lz4
, as a 64-bit shared library.
To use the draft APIs, you may build czmq
with draft
feature:
vcpkg install czmq[draft]
If you are an adventurer, and want to always use the latest version of czmq
, pass an extra --head
option:
vcpkg.exe install czmq --head
These commands will also print out instructions on how to use the library from your MSBuild or CMake-based projects.
Requirements
ZeroMQ 2.2.x or later. We recommend to use ZeroMQ >= 3.
C++11 compliant compiler. (g++ >= 4.7)
The command line client and the tests also require libboost.
Installation
Installation can be done by the standard make && make install. If the boost
unittest framework is installed, check and installcheck can be run for sanity
checking. To use ZMQ4 security feature install libsodium and libzmq –with-libsodium
as shown below before ZMQPP.
Build, check, and install libsodium
git clone git://github.com/jedisct1/libsodium.git
cd libsodium
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
cd ../
Build, check, and install the latest version of ZeroMQ
git clone git://github.com/zeromq/libzmq.git
cd libzmq
./autogen.sh
./configure –with-libsodium && make
sudo make install
sudo ldconfig
cd ../
Now install ZMQPP
git clone git://github.com/zeromq/zmqpp.git
cd zmqpp
make
make check
sudo make install
make installcheck
The most commonly useful overrides are setting CXX, to change the compiler
used, and PREFIX to change install location. The CXX prefix should be used on
all targets as the compiler version is used in the build path. PREFIX is only
relevant for the install target.
Example download
is missing for cppzmq
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/cpp/cppzmq
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Building and installation
Building requires a recent version of CMake (2.8.12 or later for Visual Studio, 2.8 or later for the rest), and a C++ compiler
which supports C++11. Currently this has been tested with —
- Xcode 5.1 on OS X 10.8
- Xcode 6 on OS X 10.9
- Xcode 6.4 on OS X 10.10
- Xcode 7.1 on OS X 10.11
- GCC 4.8 + Boost 1.48 on CentOS 6
- GCC 4.8 + Boost 1.53 on CentOS 7
- GCC 4.8 on Arch Linux and Ubuntu
- GCC 4.8 on Ubuntu
- GCC 5.3 + Boost 1.60 on Ubuntu
- Microsoft Visual Studio 2013 on Windows Server 2008 R2
Library dependencies are —
- Boost 1.48 or later
- ZeroMQ 4.0.x
Tests and example code require —
- Boost 1.54 or later
To build on Linux / OS X —
$ mkdir build && cd build
$ cmake ..
$ make
$ make test
$ make install
To build on Windows —
> mkdir build
> cd build
> cmake ..
> cmake --build . --config Release
> ctest . -C Release
You can also open Visual Studio solution from build
directory after invoking CMake.
To change the default install location use -DCMAKE_INSTALL_PREFIX
when invoking CMake.
To change where the build looks for Boost and ZeroMQ use -DBOOST_ROOT=<my custom Boost install>
and -DZMQ_ROOT=<my custom ZeroMQ install>
when invoking CMake. Or set BOOST_ROOT
and ZMQ_ROOT
environment variables.
Example download
is missing for czmqpp
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/cpp/czmqpp
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Example download
is missing for fbzmq
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/cpp/fbzmq
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Installation
You can download NetMQ via NuGet.
Example download
is missing for clrzmq4
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/csharp/clrzmq4
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Install
You can install chumak
from hex.pm by including the following in your rebar.config
:
{deps,[
{chumak, "X.Y.Z"}
]}.
where X.Y.Z is one of the release versions.
For more info on rebar3 dependencies see the rebar3 docs.
Example download
is missing for ezmq
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/erlang/ezmq
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Example download
is missing for erlang-czmq
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/erlang/erlang-czmq
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Example download
is missing for FsNetMQ
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/fsharp/fsnetmq
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Example download
is missing for fszmq
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/fsharp/fszmq
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Requirements
zmq4 is just a wrapper for the ZeroMQ library. It doesn’t include the
library itself. So you need to have ZeroMQ installed, including its
development files. On Linux and Darwin you can check this with ($
is
the command prompt):
$ pkg-config --modversion libzmq
4.3.1
The Go compiler must be able to compile C code. You can check this
with:
$ go env CGO_ENABLED
1
You can’t do cross-compilation. That would disable C.
Windows
Build with CGO_CFLAGS
and CGO_LDFLAGS
environment variables, for example:
$env:CGO_CFLAGS='-ID:/dev/vcpkg/installed/x64-windows/include'
$env:CGO_LDFLAGS='-LD:/dev/vcpkg/installed/x64-windows/lib -l:libzmq-mt-4_3_4.lib'
Deploy result program with
libzmq-mt-4_3_4.dll
Install
go get github.com/pebbe/zmq4
Install
Dependencies
- libsodium
- libzmq
- czmq
For CZMQ master
go get github.com/zeromq/goczmq
A Note on Build Tags
The CZMQ library includes experimental classes that are not built by default, but can be built
by passing --enable-drafts
to configure. Support for these draft classes are being added
to goczmq. To build these features against a CZMQ that has been compiled with --enable-drafts
,
use go build -tags draft
.
For CMZQ = 4.2
go get gopkg.in/zeromq/goczmq.v4
Note: CZMQ 4.2 is has not been released yet.
For CZMQ Before 4.0
go get gopkg.in/zeromq/goczmq.v1
Example download
is missing for zeromq4-haskell
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/haskell/zeromq4-haskell
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Usage
Maven
Add it to your Maven project’s pom.xml
:
<dependency>
<groupId>org.zeromq</groupId>
<artifactId>jeromq</artifactId>
<version>0.5.3</version>
</dependency>
<!-- for the latest SNAPSHOT -->
<dependency>
<groupId>org.zeromq</groupId>
<artifactId>jeromq</artifactId>
<version>0.6.0-SNAPSHOT</version>
</dependency>
<!-- If you can't find the latest snapshot -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Ant
To generate an ant build file from pom.xml
, issue the following command:
Example download
is missing for JZMQ
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/java/jzmq
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Example download
is missing for jczmq
. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
example_dir=content/docs/examples/java/jczmq
cd zeromq.org && mkdir -p $example_dir
[ -s $example_dir/index.md ] || cat >$example_dir/index.md <<'EOF'
---
headless: true
---
EOF
cp archetypes/examples/download.md
$example_dir/download.md
Installation
Install ZeroMQ.js with prebuilt binaries:
npm install zeromq@6.0.0-beta.17
Requirements for using prebuilt binaries:
- Node.js 10.2+ or Electron 3+ (requires a N-API version 3+)
Prebuilt binaries
The following platforms have a prebuilt binary available:
- Linux on x86-64 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
If a prebuilt binary is not available for your platform, installing will attempt to start a build from source.
Building from source
If a prebuilt binary is unavailable or if you want to pass certain options during build, you can build this package from source.
Make sure you have the following installed before attempting to build from source:
- Node.js 10+ or Electron 3+
- A working C++17 compiler toolchain with make
- Python 3 with Node 12.13+ (or legacy Python 2.7)
- CMake 2.8+
- curl
To install from source:
npm install zeromq@6.0.0-beta.17 --build-from-source
If you want to link against a shared ZeroMQ library, you can build skip downloading libzmq
and link with the
installed library instead as follows:
npm install zeromq@6.0.0-beta.17 --zmq-shared
If you wish to use any DRAFT sockets then it is also necessary to compile the library from source:
npm install zeromq@6.0.0-beta.17 --zmq-draft
INSTALL
cpanm -v ZMQ::FFI
Downloading
Unless you specifically want to develop PyZMQ, we recommend downloading
the PyZMQ source code or wheels from
PyPI,
or install with conda.
You can also get the latest source code from our GitHub repository, but
building from the repository will require that you install recent Cython.
Building and installation
For more detail on building pyzmq, see our Wiki.
We build wheels for macOS, Windows, and Linux, so you can get a binary on those platforms with:
pip install pyzmq
but compiling from source with pip install pyzmq
should work in most environments.
Especially on macOS, make sure you are using the latest pip (≥ 8), or it may not find the right wheels.
If the wheel doesn’t work for some reason, or you want to force pyzmq to be compiled
(this is often preferable if you already have libzmq installed and configured the way you want it),
you can force installation with:
pip install --no-binary=:all: pyzmq
When compiling pyzmq (e.g. installing with pip on Linux),
it is generally recommended that zeromq be installed separately,
via homebrew, apt, yum, etc:
# Debian-based
sudo apt-get install libzmq3-dev
# RHEL-based
sudo yum install libzmq3-devel
If this is not available, pyzmq will try to build libzmq as a Python Extension,
though this is not guaranteed to work.
Building pyzmq from the git repo (including release tags on GitHub) requires Cython.
Installation
Install libzmq.
If the gem installation complains that it cannot find libzmq or headers, simply pass the location of your libzmq installation to the gem install command:
gem install zmq -- --with-zmq-dir=/opt/local
On Windows add a parameter for the libs. For example:
gem install zmq -- --with-zmq-dir=c:/src/zeromq-4.3.2 --with-zmq-lib=c:/src/zeromq-4.3.2/src/.libs
Adding to build process
Determine the specific release tag of the library to use in the project.
Add to the build.zig.zon
file, e.g. for Zig 0.11:
.{
.dependencies = .{
.zzmq = .{
.url = "https://github.com/nine-lives-later/zzmq/archive/refs/tags/v0.1.0-zig0.11.tar.gz",
.hash = "122080e22e9823dc0a4567c71553c4884978a33877c9b3d46f4594ca5f299d534f9b",
},
},
}
Note: Should the hash be wrong, remove the .hash
field and the compiler error will show the correct value. Starting with Zig 0.12 you can also use zig fetch zzmq <url>
.
It is also required to add it to the build.zig
file:
const zzmq = b.dependency("zzmq", .{
.target = target,
.optimize = optimize,
});
// Note: starting with zig 0.12 the function will be
// `exe.root_module.addImport` instead of `exe.addModule`
exe.addModule("zzmq", zzmq.module("zzmq"));
exe.linkSystemLibrary("czmq");
exe.linkLibC();
Installing local dependencies
Installing CZMQ development library version 4.0 or higher is also required:
# Building on Ubuntu, PoP_OS, ZorinOS, etc.
sudo apt install libczmq-dev
# Running on Ubuntu, PoP_OS, ZorinOS, etc.
sudo apt install libczmq
How to Install ZeroMQ on Windows 10
Introduction
ZeroMQ is a messaging library that allows distributed applications to communicate with each other. In this tutorial, we will go through the steps to install ZeroMQ on a Windows 10 machine.
Prerequisites
Before we begin the installation process, you should have the following:
- A Windows 10 machine
- Administrative access to the machine
- A web browser to download files
Steps
- Download ZeroMQ
First, download the ZeroMQ package from the official website. Go to http://zeromq.org/ and click on «DOWNLOADS» in the top navigation bar. From the dropdown list, choose «Stable Releases» and click on the link for your desired version. We will choose version 4.3.5 for this tutorial.
- Extract ZeroMQ
After downloading the package, extract the files to a directory of your choice. We will create a new directory called «zeromq» on our C drive, and extract the files there.
- Setup System Environment Variables
To use ZeroMQ, you will need to set up some environment variables. First, open the Start Menu and search for «Environment Variables». Click on «Edit the system environment variables».
In the System Properties window that opens, click on the «Environment Variables» button.
Under the «System Variables» section, click on «New» and enter the following:
- Variable name:
ZMQ_HOME
- Variable value:
C:\zeromq
(or the directory where you extracted ZeroMQ)
Next, edit the «Path» variable and add the following to the end of the value:
;%ZMQ_HOME%\bin
Click «OK» to save the changes.
- Restart Computer
For the changes to take effect, you will need to restart your computer.
- Verify Installation
After restarting your computer, open a command prompt and enter the following command:
zmq-config
If ZeroMQ is installed and configured correctly, you should see output similar to the following:
Usage: /usr/bin/zmq-config [OPTIONS]
Know options are: [--prefix[=DIR]] [--exec-prefix[=DIR]] [--libs] [--cflags]
If no option is specified zmq-config prints values suitable for
interfacing with installed zmq library.
Congratulations! You have successfully installed ZeroMQ on your Windows 10 machine.
Conclusion
In this tutorial, we have gone through the steps to install ZeroMQ on a Windows 10 machine. ZeroMQ is a powerful messaging library that can be used to develop distributed applications. If you encounter any issues during the installation process, be sure to refer to the official documentation for help.
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!
Currently, I am working on a project that is a Qt application targeting modern Linux desktop distributions and Windows. The application needs to communicate with some onboard hardware via ZMQ. Normally in a Windows only .Net environment, I’d use NetMQ and C# and be off the the races, but that just wasn’t an option here — partially because I want to work on Linux and partially because Linux-based systems are becoming increasingly common in the aerospace field. The requirement to run cross-platform lead me through a long period of evaluating different technical stacks including Qt. Ultimately, I went with Qt and things were going great. On my Pop!_OS (read Ubuntu) Linux development machine installing ZMQ was just an `apt install` and `make`
away. Windows was another story.
Here’s the unfortunate but obviously reality — Windows is not a POSIX compliant operating system. For better or worse Windows is its own beautiful little snowflake, complete with DLLs. As you might get it was those DLLs that caused all the mischief here. I started as any naive developer using Windows might by finding an MSI for ZMQ and going to town with that. After integrated the generated .lib and DLL, I was getting this error at run-time only.
After days of seeing this it became something out of Poe, a telltale error dialog. I know that the most likely cause of this error appearing at run-time and not being caught by the compiler was that it must have been an error reading into a DLL and since I only had one external dependency at the time I knew the culprit had to be libzmq.
Though it took me a day or so to figure it out I finally found a good way to install ZMQ correctly so that it can be used for Qt / C++ development. The first step is to clone the git repo for VCPKG in PowerShell: `git clone https://github.com/Microsoft/vcpkg.git`. From the `cd` into the vcpkg directory and run these commands in order:
.\bootstrap-vcpkg.bat
.\vcpkg integrate install
.\vcpkg install zeromq:x64-windows
.\vcpkg integrate install
From there you can either link to the DLL and pull in the .lib the DLL. They will be somewhere like: `C:\\Users\vcpkg\installed\x64-windows\debug\bin\libzmq-mt-gd-4_3_1.dll` and the .lib will be in the same root but under the lib or include directory next to the bin directory listed above. From there you’ll need to clean and rebuild your project on QtCreator, then debug it. If you have your paths correct, then you’ll be ready to send messages over ZMQ with the best of them.
I hope this helps! Let me know what you think on Twitter and do reach out to me at The Mad Botter if you have any software development needs.
Hi! I’m Mike! I’m a software engineer who codes at The Mad Botter INC. You might know me from Coder Radio or The Mike Dominick Show. Drop me a line if you’re interested in having some custom mobile or web development done.
Follow Me
ØMQ bindings for node.js.
Project Status
This project has moved!
The same people (and more) who brought you zmq
now bring you zeromq
, under the
official zeromq
GitHub organization.
- GitHub: https://github.com/zeromq/zeromq.js
- NPM: https://www.npmjs.com/package/zeromq
We suggest all users migrate to this fork. Issues and Pull Requests on this
(JustinTulloss/zeromq.node) repository will no longer be handled by the core team.
Installation
on Windows:
First install Visual Studio and either
Node.js or io.js.
Ensure you’re building zmq from a conservative location on disk, one without
unusual characters or spaces, for example somewhere like: C:\sources\myproject
.
Installing the ZeroMQ library is optional and not required on Windows. We
recommend running npm install
and node executable commands from a
github for windows shell or similar environment.
installing on Unix/POSIX (and osx):
First install pkg-config
and the ZeroMQ library.
This module is compatible with ZeroMQ versions 2, 3 and 4. The installation
process varies by platform, but headers are mandatory. Most Linux distributions
provide these headers with -devel
packages like zeromq-devel
or
zeromq3-devel
. Homebrew for OS X provides versions 4 and 3 with packages
zeromq
and zeromq3
, respectively. A
Chris Lea PPA
is available for Debian-like users who want a version newer than currently
provided by their distribution. Windows is supported but not actively
maintained.
Note: For zap support with versions >=4 you need to have libzmq built and linked
against libsodium. Check the Travis configuration for a list of what is tested
and therefore known to work.
with your platform-specifics taken care of, install and use this module:
Examples
Push/Pull
// producer.js var zmq = require('zmq') , sock = zmq.socket('push'); sock.bindSync('tcp://127.0.0.1:3000'); console.log('Producer bound to port 3000'); setInterval(function(){ console.log('sending work'); sock.send('some work'); }, 500);
// worker.js var zmq = require('zmq') , sock = zmq.socket('pull'); sock.connect('tcp://127.0.0.1:3000'); console.log('Worker connected to port 3000'); sock.on('message', function(msg){ console.log('work: %s', msg.toString()); });
Pub/Sub
// pubber.js var zmq = require('zmq') , sock = zmq.socket('pub'); sock.bindSync('tcp://127.0.0.1:3000'); console.log('Publisher bound to port 3000'); setInterval(function(){ console.log('sending a multipart message envelope'); sock.send(['kitty cats', 'meow!']); }, 500);
// subber.js var zmq = require('zmq') , sock = zmq.socket('sub'); sock.connect('tcp://127.0.0.1:3000'); sock.subscribe('kitty cats'); console.log('Subscriber connected to port 3000'); sock.on('message', function(topic, message) { console.log('received a message related to:', topic, 'containing message:', message); });
Monitoring
You can get socket state changes events by calling to the monitor
function.
The supported events are (see ZMQ docs for full description):
- connect —
ZMQ_EVENT_CONNECTED
- connect_delay —
ZMQ_EVENT_CONNECT_DELAYED
- connect_retry —
ZMQ_EVENT_CONNECT_RETRIED
- listen —
ZMQ_EVENT_LISTENING
- bind_error —
ZMQ_EVENT_BIND_FAILED
- accept —
ZMQ_EVENT_ACCEPTED
- accept_error —
ZMQ_EVENT_ACCEPT_FAILED
- close —
ZMQ_EVENT_CLOSED
- close_error —
ZMQ_EVENT_CLOSE_FAILED
- disconnect —
ZMQ_EVENT_DISCONNECTED
All events get 2 arguments:
-
fd
— The file descriptor of the underlying socket (if available) -
endpoint
— The underlying socket endpoint
A special monitor_error
event will be raised when there was an error in the monitoring process, after this event no more
monitoring events will be sent, you can try and call monitor
again to restart the monitoring process.
monitor(interval, numOfEvents)
Will create an inproc PAIR socket where zmq will publish socket state changes events, the events from this socket will
be read every interval
(defaults to 10ms).
By default only 1 message will be read every interval, this can be configured by using the numOfEvents
parameter,
where passing 0 will read all available messages per interval.
unmonitor()
Stop the monitoring process
example
// Create a socket var zmq = require('zmq'); socket = zmq.socket('req'); // Register to monitoring events socket.on('connect', function(fd, ep) {console.log('connect, endpoint:', ep);}); socket.on('connect_delay', function(fd, ep) {console.log('connect_delay, endpoint:', ep);}); socket.on('connect_retry', function(fd, ep) {console.log('connect_retry, endpoint:', ep);}); socket.on('listen', function(fd, ep) {console.log('listen, endpoint:', ep);}); socket.on('bind_error', function(fd, ep) {console.log('bind_error, endpoint:', ep);}); socket.on('accept', function(fd, ep) {console.log('accept, endpoint:', ep);}); socket.on('accept_error', function(fd, ep) {console.log('accept_error, endpoint:', ep);}); socket.on('close', function(fd, ep) {console.log('close, endpoint:', ep);}); socket.on('close_error', function(fd, ep) {console.log('close_error, endpoint:', ep);}); socket.on('disconnect', function(fd, ep) {console.log('disconnect, endpoint:', ep);}); // Handle monitor error socket.on('monitor_error', function(err) { console.log('Error in monitoring: %s, will restart monitoring in 5 seconds', err); setTimeout(function() { socket.monitor(500, 0); }, 5000); }); // Call monitor, check for events every 500ms and get all available events. console.log('Start monitoring...'); socket.monitor(500, 0); socket.connect('tcp://127.0.0.1:1234'); setTimeout(function() { console.log('Stop the monitoring...'); socket.unmonitor(); }, 20000);
Detaching from the event loop
You may temporarily disable polling on a specific ZMQ socket and let the node.js
process to terminate without closing sockets explicitly by removing their event loop
references. Newly created sockets are already ref()
-ed.
unref()
Detach the socket from the main event loop of the node.js runtime.
Calling this on already detached sockets is a no-op.
ref()
Attach the socket to the main event loop.
Calling this on already attached sockets is a no-op.
Example
var zmq = require('zmq'); socket = zmq.socket('sub'); socket.bindSync('tcp://127.0.0.1:1234'); socket.subscribe(''); socket.on('message', function(msg) { console.log(msg.toString(); }); // Here blocks indefinitely unless interrupted. // Let it terminate after 1 second. setTimeout(function() { socket.unref(); }, 1000);
Running tests
Install dev deps:
$ git clone https://github.com/JustinTulloss/zeromq.node.git zmq && cd zmq $ npm i
Build:
# on unix: $ make # building on windows: > npm i
Test:
# on unix: $ make test # testing on windows: > npm t
Running benchmarks
Benchmarks are available in the perf
directory, and have been implemented
according to the zmq documentation:
How to run performance tests
In the following examples, the arguments are respectively:
- the host to connect to/bind on
- message size (in bytes)
- message count
You can run a latency benchmark by running these two commands in two separate
shells:
node ./local_lat.js tcp://127.0.0.1:5555 1 100000
node ./remote_lat.js tcp://127.0.0.1:5555 1 100000
And you can run throughput tests by running these two commands in two
separate shells:
node ./local_thr.js tcp://127.0.0.1:5555 1 100000
node ./remote_thr.js tcp://127.0.0.1:5555 1 100000
Running make perf
will run the commands listed above.
Не врубается расширение в WAMP(php7) впрочем скачал отдельно php7 (64 TS) версия. Ошибка Warning: PHP Startup: Unable to load dynamic library ‘C:/123/ext/php_zmq.dll’ — ═х эрщфхэ єърчрээ√щ ьюфєы№. in Unknown on line 0
Поискав — нашел, что расширение не подходит для php7, но https://pecl.php.net/package/zmq/1.1.3/windows — Introduces PHP7 support.
На php 5.6 завелось как часы (требуется именно PHP7)
-
Вопрос задан
-
1478 просмотров
Пригласить эксперта
У меня все работает, версия PHP 7.0.2.
Установка ZMQ для Windows:
1. Скачать архив для своей версии PHP из сайта https://pecl.php.net/package/zmq/1.1.3/windows
2. Скопировать из архива файл php_zmq.dll в папку с разширениями (напр. С:\PHP\ext)
3. Добавить php_zmq.dll в php.ini (extension=php_zmq.dll)
3. Скопировать из архива libzmq.dll и libsodium.dll в root директорию PHP (напр. C:\PHP)
4. Перезапустить apache.
Поддержка php7 доступно в бета версии. Вы точно используете именно эту бету?
Войдите, чтобы написать ответ
-
Показать ещё
Загружается…