How to use pm2-axon-rpc - 10 common examples

To help you get started, we’ve selected a few pm2-axon-rpc 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 Tjatse / pm2-ant / lib / pm.js View on Github external
pm._rpc = function (opts) {
  var req = axon.socket("req"),
    rpc_sock = req.connect(opts.sockPath),
    rpc_client = new rpc.Client(req);

  // Connect RPC server.
  rpc_sock.on('connect', function () {
    // Execute request.
    var waterfalls = opts.events.map(function (event) {
      return function (next) {
        var cb = typeof event[event.length - 1] == 'function' ? event.pop() : null;
        if (cb) {
          event.push(function () {
            // Wrap arguments, no [].slice (avoid leak)!!!
            var args = new Array(arguments.length);
            for (var i = 0; i < args; i++) {
              args[i] = arguments[i];
            }
            cb.apply(null, arguments);
            next();
github Tjatse / pm2-gui / lib / pm.js View on Github external
pm._rpc = function (opts) {
  var req = axon.socket('req')
  var rpcSock = req.connect(opts.sockPath)
  var rpcClient = new rpc.Client(req)

  // Connect RPC server.
  rpcSock.on('connect', function () {
    // Execute request.
    var waterfalls = opts.events.map(function (event) {
      return function (next) {
        var cb = typeof event[event.length - 1] === 'function' ? event.pop() : null
        if (cb) {
          event.push(function () {
            // Wrap arguments, no [].slice (avoid leak)!!!
            var args = new Array(arguments.length)
            for (var i = 0; i < args; i++) {
              args[i] = arguments[i]
            }
            cb.apply(opts.context, arguments)
            next()
github jitta / spinal / lib / router.js View on Github external
Router.prototype.addNode = function(data) {
  if(data.namespace && data.namespace[0] === '$')
    return debug('[tmp-node] connected ' + data.namespace + '(' + data.id + ')')

  this.nodes[data.id] = _.clone(data)
  var obj = this.nodes[data.id]
  obj.req = axon.socket('req')
  obj.client = new rpc.Client(obj.req)
  obj.req.connect(data.port, data.hostname)
  obj.timer = new Measured.Timer()
  // add methods to routing
  for(var i in data.methods){
    this.addMethod(data.methods[i], data.id)
  }
  // namespace collection
  if (this.namespace[data.namespace]){
    this.namespace[data.namespace].push(data.id)
  }else{
    this.namespace[data.namespace] = [data.id]
  }
  this.version = crypto.createHash('md5')
    .update(_.keys(this.routing).join(',')).digest('hex')
  // this.syncAll()
}
github LiskHQ / lisk-sdk / framework / src / controller / channels / child_process_channel.js View on Github external
async registerToBus(socketsPath) {
		this.subSocket = axon.socket('sub-emitter');
		this.subSocket.connect(socketsPath.pub);

		this.busRpcSocket = axon.socket('req');
		this.busRpcSocket.connect(socketsPath.rpc);
		this.busRpcClient = new RPCClient(this.busRpcSocket);
		this.busRpcClientCallPromisified = util.promisify(this.busRpcClient.call);

		// Channel Publish Socket is only required if the module has events
		if (this.eventsList.length > 0) {
			this.pubSocket = axon.socket('pub-emitter');
			this.pubSocket.connect(socketsPath.sub);
		}

		// Channel RPC Server is only required if the module has actions
		if (this.actionsList.length > 0) {
			this.rpcSocketPath = `unix://${socketsPath.root}/${this.moduleAlias}_rpc.sock`;

			this.rpcSocket = axon.socket('rep');
			this.rpcSocket.bind(this.rpcSocketPath);
			this.rpcServer = new RPCServer(this.rpcSocket);
github LiskHQ / lisk-sdk / framework / src / controller / channels / child_process_channel.js View on Github external
this.busRpcClient = new RPCClient(this.busRpcSocket);
		this.busRpcClientCallPromisified = util.promisify(this.busRpcClient.call);

		// Channel Publish Socket is only required if the module has events
		if (this.eventsList.length > 0) {
			this.pubSocket = axon.socket('pub-emitter');
			this.pubSocket.connect(socketsPath.sub);
		}

		// Channel RPC Server is only required if the module has actions
		if (this.actionsList.length > 0) {
			this.rpcSocketPath = `unix://${socketsPath.root}/${this.moduleAlias}_rpc.sock`;

			this.rpcSocket = axon.socket('rep');
			this.rpcSocket.bind(this.rpcSocketPath);
			this.rpcServer = new RPCServer(this.rpcSocket);

			this.rpcServer.expose('invoke', (action, cb) => {
				this.invoke(action)
					.then(data => cb(null, data))
					.catch(error => cb(error));
			});

			this.rpcServer.expose('invokePublic', (action, cb) => {
				this.invokePublic(action)
					.then(data => cb(null, data))
					.catch(error => cb(error));
			});
		}

		return this.setupSockets();
	}
github DiffBit / CryptoTradePlatform / node_modules / pm2 / lib / Interactor / Daemon.js View on Github external
activateRPC : function() {
    console.log('Launching Interactor exposure');

    var self          = this;
    var rep           = axon.socket('rep');
    var daemon_server = new rpc.Server(rep);
    var sock          = rep.bind(cst.INTERACTOR_RPC_PORT);

    daemon_server.expose({
      kill : function(cb) {
        console.log('Killing interactor');
        cb(null);
        return Daemon.exit();
      },
      passwordSet : function(cb) {
        global._pm2_password_protected = true;
        return cb(null);
      },
      getInfos : function(cb) {
        if (self.opts &&
            self.opts.DAEMON_ACTIVE == true)
          return cb(null, {
github Unitech / pm2-interface / lib / index.js View on Github external
//if (!(this instanceof Bash)) return new Bash(opts);
  var self = this;

  EventEmitter.call(this);

  this.sub_port  = sub_port;
  this.rpc_port  = rpc_port;
  this.bind_host = bind_host;

  var sub = axon.socket('sub-emitter');
  var sub_sock = this.sub_sock = sub.connect(sub_port);
  this.bus      = sub;

  var req = axon.socket("req");
  var rpc_sock = this.rpc_sock = req.connect(rpc_port);
  this.rpc_client = new rpc.Client(req);

  this.rpc = {};

  /**
   * Disconnect socket connections. This will allow Node to exit automatically.
   * Further calls to PM2 from this object will throw an error.
   */
  this.disconnect = function () {
    self.sub_sock.close();
    self.rpc_sock.close();
  };

  /**
   * Generate method by requesting exposed methods by PM2
   * You can now control/interact with PM2
   */
github LiskHQ / lisk-sdk / framework / src / controller / bus.js View on Github external
if (this.actions[actionFullName]) {
				throw new Error(
					`Action "${actionFullName}" already registered with bus.`,
				);
			}

			this.actions[actionFullName] = actions[actionName];
		});

		let { channel } = options;

		if (options.rpcSocketPath) {
			const rpcSocket = axon.socket('req');
			rpcSocket.connect(options.rpcSocketPath);
			channel = new RPCClient(rpcSocket);
			this.rpcClients[moduleAlias] = rpcSocket;
		}

		this.channels[moduleAlias] = {
			channel,
			actions,
			events,
			type: options.type,
		};
	}
github taurusai / kungfu / resources / cover / pm2 / lib / Client.js View on Github external
Client.prototype.launchRPC = function launchRPC(cb) {
  var self = this;
  debug('Launching RPC client on socket file %s', this.rpc_socket_file);
  var req      = axon.socket('req');
  this.client  = new rpc.Client(req);

  var connectHandler = function() {
    self.client.sock.removeListener('error', errorHandler);
    debug('RPC Connected to Daemon');
    if (cb) {
      setTimeout(function() {
        cb(null);
      }, 4);
    }
  };

  var errorHandler = function(e) {
    self.client.sock.removeListener('connect', connectHandler);
    if (cb) {
      return cb(e);
    }
github taurusai / kungfu / resources / cover / pm2 / lib / Client.js View on Github external
Client.prototype.pingDaemon = function pingDaemon(cb) {
  var req    = axon.socket('req');
  var client = new rpc.Client(req);
  var that = this;

  debug('[PING PM2] Trying to connect to server');

  client.sock.once('reconnect attempt', function() {
    client.sock.close();
    debug('Daemon not launched');
    process.nextTick(function() {
      return cb(false);
    });
  });

  client.sock.once('error', function(e) {
    if (e.code === 'EACCES') {
      fs.stat(that.conf.DAEMON_RPC_PORT, function(e, stats) {
        if (stats.uid === 0) {

pm2-axon-rpc

Remote procedure calls built on top of axon.

MIT
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis

Popular pm2-axon-rpc functions