Axon

Axon is a message-oriented socket library for node.js heavily inspired by zeromq. For a light-weight UDP alternative you may be interested in punt.

Installation

$ npm install axon

Features

  • message oriented
  • automated reconnection
  • light-weight wire protocol
  • mixed-type arguments (strings, objects, buffers, etc)
    • unix domain socket support
  • Fast (~800 MB /s ~500,000 messages/s)

Events

  • close when server or connection is closed
  • error (err) when an un-handled socket error occurs
    • ignored error (err) when an axon-handled socket error occurs, but is ignored
    • socket error (err) emitted regardless of handling, for logging purposes
    • reconnect attempt when a reconnection attempt is made
  • connect when connected to the peer, or a peer connection is accepted
  • disconnect when an accepted peer disconnects
  • bind when the server is bound
  • drop (msg) when a message is dropped due to the HWM
    • flush (msgs) queued when messages are flushed on connection

Patterns

  • push / pull
  • pub / sub
  • req / rep
  • pub-emitter / sub-emitter

Mixed argument types

Backed by node-amp-message you may pass strings, objects, and buffers as arguments.

push.send('image', { w: 100.h: 200 }, imageBuffer);
pull.on('message'.function(type, size, img){});
Copy the code

Push / Pull

PushSockets distribute messages round-robin:

var axon = require('axon');
var sock = axon.socket('push');

sock.bind(3000);
console.log('push server started');

setInterval(function(){
    sock.send('hello'); }},150);
});
}, 500);
});
});
});
});
});
});
}, 500);
});
});
});
Copy the code