zmq-prebuilt
!zmq-static: Your statically linked ØMQ bindings for Node.js.
ØMQ provides handy functionality when working with sockets.
zmq-static will bundle ØMQ, allowing you to package ØMQ in your Node.js or Electron aplication.
zmq-static simplifies creating communications for a Node.js application by providing well-tested, ready to use ØMQ bindings. zmq-static supports all major operating systems, including:
Replace require(zmq)
in your code base with zmq-static
. That's it.
To set up zmq-static
, fork this repository and
clone your fork to your system. Be sure you have git-lfs
and python2
installed.
Prerequisites for Linux and OS X
If you are running on Linux or OS X, you will need to have automake
,
autoconf
, wget
and libtool
installed. For Linux, use your distribution's
package manager to install. On OS X, these can be installed using
Homebrew and using the Homebrew command brew install
command. For example, install wget
with brew install wget
.
Prerequisites for Windows
On Windows you'll need a C++ compiler, use on of the options provided here.
Install zmq-static
with the following:
npm install
Run the test suite using:
npm test
Several example applications are found in the examples
directory. Use
node
to run an example. To run the 'subber' application, enter the
following:
node examples/subber.js
This example demonstrates how a producer pushes information onto a socket and how a worker pulls information from the socket.
producer.js
// producer.js
var zmq = require('zmq-static')
, 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
// worker.js
var zmq = require('zmq-static')
, 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());
});
This example demonstrates using zmq-static
in a classic Pub/Sub,
Publisher/Subscriber, application.
Publisher: pubber.js
// pubber.js
var zmq = require('zmq-static')
, 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);
Subscriber: subber.js
// subber.js
var zmq = require('zmq-static')
, 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);
});