Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Node.js bindings to the zeromq library

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
test
.gitignore
LICENSE
README.md
binding.cc
package.json
wscript
zeromq.js

README.md

This is alpha quality. Proceed with caution

This library gives you experimental bindings to ØMQ from node.js.

Dependencies

Some bleeding edge dependencies are required:

  • node.js. Should work with at least 0.3.
  • ØMQ. Should work with at least 2.1.

At the time of writing, ØMQ 2.1 has not been released, so you'll have to build it from its github repositories, while node.js 0.3 has been released but is still officially "unstable."

To Build

 $ node-waf configure build

API

The API contains elements of the ØMQ API. You should refer to it for in depth detail of the expected behaviors of the system. These methods will never return error codes, but may throw an exception if any of the errors described in the ØMQ documentation occur.

First, include the module:

zeromq = require('zeromq');

After that, you can create sockets with:

socket = zeromq.createSocket('req');

Using ØMQ sockets

A socket is where the action happens. You can send and receive things and it is oh such fun.

Constructor - function(type)

  • type - A string describing the type of socket. You can read about the different socket types here. The name you use here matches the names of the ZMQ_* constants, sans the ZMQ_ prefix.

Methods

  • connect(address) - Connect to another socket. address should be a string as described in the ØMQ API docs. This method is not asynchronous because it is non-blocking. ØMQ will use the provided address when it's necessary and will not block here.
  • bind(address, callback) - Bind to a socket to wait for incoming data. address should be a string as described in the ØMQ API docs. callback will be called when binding is complete and takes one argument, a string describing any errors.
  • send(message, ...) - message is a string to send across the wire. The message is not sent immediately, but there is no callback indicating when it has been transmitted. Have your server ack or something if you care that much.

    The message must be either a String or a Buffer object, or bad things will happen. If you provide more than one argument to send, then a multipart ØMQ message will be sent.

  • close() - Closes the socket

Events

  • message - A message was received. The arguments are the parts of the message. So, for example, if you have an xrep socket with plain req sockets on the other end, you can do something like

    socket.on('message', function(envelope, blank, data) { socket.send(envelope, blank, compute_reply_for(data)); }

  • error - There was some error. The only argument is an exception explaining what the error was.

Testing

Tests are pretty incomplete right now, but to run what's there:

$ node examples/simple-server.js
# in another terminal:
$ npm install vows
$ vows

Licensing

Licensed under the very permissive MIT License.

Something went wrong with that request. Please try again.