How to use axon - 10 common examples

To help you get started, we’ve selected a few axon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fluidecho / kurunt / lib / inputs / http / messenger.js View on Github external
mq_sockets[c]['apikey'] = apikey;
		
		
		// if guaranteed delivery and pattern is push, change to req.
		if ( GUARANTEE_DELIVERY ) {
			if ( zmq_pattern === 'push' ) {
				zmq_pattern = 'req';
			}
			if ( zmq_pattern === 'pull' ) {
				zmq_pattern = 'rep';
			}			
		}
		logging.log('messenger:'+processID+'@inputs> zmq_pattern: ' + zmq_pattern );
		
		
		mq_sockets[c]['socket'] = mq.socket(zmq_pattern);
		if ( topology['connections'][c]['zmq_socket'] == 'bind' ) {
			logging.log('messenger:'+processID+"@inputs> zmq binding for apikey: " + apikey + ", namespace: " + namespace + ", at: " + zmq_pattern + "@" + zmq_address);
			mq_sockets[c]['socket'].bind(topology['connections'][c]['zmq_address']);
		} else {
			logging.log('messenger:'+processID+"zmq connecting for apikey: " + apikey + ", namespace: " + namespace + ", at: " + zmq_pattern + "@" + zmq_address);
			mq_sockets[c]['socket'].connect(topology['connections'][c]['zmq_address']);	
		}
		
		mq_sockets[c]['socket'].on('disconnect', function(s){
			logging.log('messenger:'+processID + '@input> ' + "disconnected: " + s._peername.port);
				//console.log('> ' + util.inspect(msg, true, 99, true));
		});			
		
		// TODO: future feature.
		if ( GUARANTEE_DELIVERY ) {	
			mq_sockets[c]['socket'].set('guarantee_delivery', false);
github fluidecho / kurunt / lib / inputs / udp / messenger.js View on Github external
mq_sockets[c]['apikey'] = apikey;
		
		
		// if guaranteed delivery and pattern is push, change to req.
		if ( GUARANTEE_DELIVERY ) {
			if ( zmq_pattern === 'push' ) {
				zmq_pattern = 'req';
			}
			if ( zmq_pattern === 'pull' ) {
				zmq_pattern = 'rep';
			}			
		}
		logging.log('messenger:'+processID+'@inputs> zmq_pattern: ' + zmq_pattern );
		
		
		mq_sockets[c]['socket'] = mq.socket(zmq_pattern);
		if ( topology['connections'][c]['zmq_socket'] == 'bind' ) {
			logging.log('messenger:'+processID+"@inputs> zmq binding for apikey: " + apikey + ", namespace: " + namespace + ", at: " + zmq_pattern + "@" + zmq_address);
			mq_sockets[c]['socket'].bind(topology['connections'][c]['zmq_address']);
		} else {
			logging.log('messenger:'+processID+"zmq connecting for apikey: " + apikey + ", namespace: " + namespace + ", at: " + zmq_pattern + "@" + zmq_address);
			mq_sockets[c]['socket'].connect(topology['connections'][c]['zmq_address']);	
		}
		
		mq_sockets[c]['socket'].on('disconnect', function(s){
			logging.log('messenger:'+processID + '@input> ' + "disconnected: " + s._peername.port);
				//console.log('> ' + util.inspect(msg, true, 99, true));
		});			
		
		// TODO: future feature.
		if ( GUARANTEE_DELIVERY ) {	
			mq_sockets[c]['socket'].set('guarantee_delivery', false);
github ircanywhere / irc-factory / lib / api.js View on Github external
Api.prototype.setupServer = function(options) {
	var self = this;

	axon.codec.define('json', {
		encode: JSON.stringify,
		decode: JSON.parse
	});
	// setup a json codec

	this._events = axon.socket('push');
	this._events.bind(options.events);
	this._events.format('json');
	// setup the events socket

	this._events.on('connect', function() {
		self.emit('metadata', {pid: process.pid, incomingPort: options.rpc, outgoingPort: options.events});
		self.emit('synchronize', {keys: _.keys(Clients)});
	});
	// setup some events for our outbound port

	this._rpc = axon.socket('sub-emitter');
	this._rpc.bind(options.rpc);
	// we also setup an inbound socket which uses the sub emitter

	this._rpc.on('createClient', function(key, client, dummy) {
		if (typeof key === 'object') {
github fluidecho / kurunt / lib / inputs / tcp / messenger.js View on Github external
mq_sockets[c]['apikey'] = apikey;
		
		
		// if guaranteed delivery and pattern is push, change to req.
		if ( GUARANTEE_DELIVERY ) {
			if ( zmq_pattern === 'push' ) {
				zmq_pattern = 'req';
			}
			if ( zmq_pattern === 'pull' ) {
				zmq_pattern = 'rep';
			}			
		}
		logging.log('messenger:'+processID+'@inputs> zmq_pattern: ' + zmq_pattern );
		
		
		mq_sockets[c]['socket'] = mq.socket(zmq_pattern);
		if ( topology['connections'][c]['zmq_socket'] == 'bind' ) {
			logging.log('messenger:'+processID+"@inputs> zmq binding for apikey: " + apikey + ", namespace: " + namespace + ", at: " + zmq_pattern + "@" + zmq_address);
			mq_sockets[c]['socket'].bind(topology['connections'][c]['zmq_address']);
		} else {
			logging.log('messenger:'+processID+"zmq connecting for apikey: " + apikey + ", namespace: " + namespace + ", at: " + zmq_pattern + "@" + zmq_address);
			mq_sockets[c]['socket'].connect(topology['connections'][c]['zmq_address']);	
		}
		
		mq_sockets[c]['socket'].on('disconnect', function(s){
			logging.log('messenger:'+processID + '@input> ' + "disconnected: " + s._peername.port);
		});			
		
		// TODO: future feature.
		if ( GUARANTEE_DELIVERY ) {	
			mq_sockets[c]['socket'].set('guarantee_delivery', false);
			mq_sockets[c]['socket'].set('commits_hwm', QUE_HWM);
github fluidecho / kurunt / lib / stores / messenger.js View on Github external
for ( c = 0; c < connections.length; c++ ) {
		//logging.log('messenger@stores> make ZMQ this connection!!!');
		
		var zmq_pattern = connections[c]['zmq_pattern'];
		// if guaranteed delivery and pattern is push, change to req.
		if ( GUARANTEE_DELIVERY ) {
			if ( zmq_pattern === 'push' ) {
				zmq_pattern = 'req';
			}
			if ( zmq_pattern === 'pull' ) {
				zmq_pattern = 'rep';
			}			
		}
		//logging.log('messenger@stores> zmq_pattern: ' + zmq_pattern );		
		
		socks[c] = mq.socket(zmq_pattern);
		//logging.log('messenger@stores> zmq_address: ' + connections[c]['zmq_address']);
		if ( connections[c]['zmq_socket'] === 'bind' ) {
 			socks[c].bind(connections[c]['zmq_address']);
 		} else {
 			socks[c].connect(connections[c]['zmq_address']);
 		}
		//logging.log('messenger@stores> messenger, ' + connections[c]['zmq_socket'] + ':' + zmq_pattern + '@' + connections[c]['zmq_address']);			

		//socks[c].format('json');

		// SET this from connected axon socket so can control pause() and resume().
		socks[c].on('connect', function(a){
			//logging.log('messenger@stores> CONNECTED --------------');
			var _this = this;
		
			exports.pause = function() {
github fluidecho / kurunt / lib / workers / messenger.js View on Github external
// if guaranteed delivery and pattern is push, change to req.
		if ( GUARANTEE_DELIVERY ) {
			if ( zmq_pattern === 'push' ) {
				zmq_pattern = 'req';
			}
			if ( zmq_pattern === 'pull' ) {
				zmq_pattern = 'rep';
			}			
		}
		logging.log('messenger@workers> zmq_pattern: ' + zmq_pattern );		
		
		if ( zmq_pattern === 'push' || zmq_pattern === 'rep' ) {
			rr++;
		}
		
		socks[c] = mq.socket(zmq_pattern);
		logging.log('messenger@workers> zmq_address: ' + connections[c]['zmq_address']);
		if ( connections[c]['zmq_socket'] === 'bind' ) {
 			socks[c].bind(connections[c]['zmq_address']);
 		} else {
 			socks[c].connect(connections[c]['zmq_address']);
 		}
		logging.log('messenger@workers> messenger, ' + connections[c]['zmq_socket'] + ':' + zmq_pattern + '@' + connections[c]['zmq_address']);		

		//socks[c].format('json');

		// SET this from connected axon socket so can control pause() and resume().
		socks[c].on('connect', function(a){
			
			var _this = this;
			
			var thisc = Number(c);
github jsbin / pennyworth / lib / server.js View on Github external
function start() {
  var local = (host === '0.0.0.0');
  var responder = axon.socket('rep');
  // responder.bind(port, host);
  if (local) {
    // this is a fudge to allow tests to work
    responder.bind(port, host);
    responder.once('bind', function () {
      log('Ready on tcp://' + host + ':' + port + '...');
      server.stop = responder.close.bind(responder);
      bind();
    }).on('connect', function () {
      log('new connection');
    });
  } else {
    // production based, connect to the remote port
    log('Trying to connect to pull from tcp://' + host + ':' + port + '...');
    responder.connect(port, host);
    responder.once('connect', function () {
github segmentio / yal / index.js View on Github external
function Logger(addrs, options) {
  if ('string' == typeof addrs) addrs = [addrs];
  options = options || {};
  this.filter = levels[filter];
  assert(addrs, 'log-server addresses required');
  this.stdio = true;
  this.indent = 2; // 2 is the default legacy value.
  // 0 is a valid value, so use hasOwnProperty.
  if (options.hasOwnProperty('indent')) {
    this.indent = options.indent;
  }
  this.sock = axon.socket('push');
  this.sock.set('hwm', options.hwm || Infinity);
  this.sock.format('json');
  this.connect(addrs);
}
github arnoldczhang / fe-guide / src / socket&rpc / simple-pm2 / rpc-client.js View on Github external
const rpc = require('axon-rpc');
const axon = require('axon');
const req = axon.socket('req');
 

var client = new rpc.Client(req);
req.connect(6666);

const cmd = process.argv[2];

if (cmd === '-s') {
  client.call('stop', function(err, cluster){
    if (!err) {
      console.log('Process disconnectd');
      process.exit(0);
    }
  });
} else {
  client.call('prepare', function(err, cluster){
github arnoldczhang / fe-guide / src / socket&rpc / simple-pm2 / daemon.js View on Github external
return function(string, encoding, fd) {
          stdout.write(JSON.stringify([(new Date()).toISOString(), string]));
        };
      }
    )(process.stderr.write);

    process.stdout.write = (function(write) {
      return function(string, encoding, fd) {
        stdout.write('\n' + JSON.stringify([(new Date()).toISOString(), string]));
      };
    })(process.stdout.write);

  if (!process.env.SLAVE) {
    const rpc = require('axon-rpc');
    const axon = require('axon');
    const rep = axon.socket('rep');
    const server = new rpc.Server(rep);
    rep.bind(6666, 'localhost');
    console.log('rpc server started at 6666');

    server.expose({
      prepare: function(fn){
        console.log('rpc connected');
        cachFn = fn;
        rpcServer(fn);
      },
      stop(fn) {
        console.log('rpc disconnectd');
        cachFn = fn;
        rpcServer(fn, 'close');
      },
    });

axon

High-level messaging & socket patterns implemented in pure js

MIT
Latest version published 8 years ago

Package Health Score

54 / 100
Full package analysis

Popular axon functions