This repository has been archived by the owner. It is now read-only.
🚫 Statically linked bindings for node.js and io.js to ZeroMQ
Clone or download
Latest commit 23762e6 Jan 20, 2017

README.md

Deprecated: All features are now available in zmq-prebuilt!

Greenkeeper badge

Build Status Build status

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:

  • OS X/Darwin
  • Linux
  • Windows

Usage

Replace require(zmq) in your code base with zmq-static. That's it.

Installation

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

Testing

Run the test suite using:

npm test

Running an example application

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

Examples using zmq-static

Push/Pull

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());
});

Pub/Sub

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);
});

Learn more about nteract

nteract animated logo