How to use the pm2-axon-rpc.Client function in pm2-axon-rpc

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 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) {
github jitta / spinal / lib / node.js View on Github external
var Spinal = function(url, options){
  var that = this
  if (typeof options == 'undefined') options = {}

  var rep = axon.socket('rep')
  var req = axon.socket('req')
  this.id = puid.generate()
  this.server = new rpc.Server(rep)
  this.client = new rpc.Client(req)
  this.jobHandler = {}
  this.broker_url = process.env.SPINAL_BROKER || url
  this.hostname = process.env.SPINAL_HOST || options.hostname
  this.port = parseInt(process.env.SPINAL_PORT || options.port)
  this.namespace = options.namespace
  this.timeout = {}
  this.initialized = false
  this.connected = false
  this._broker_data = {
    version: null,
    methods: []
  }
  this.config = {}
  this.nock = new Nock(this)
  if (options.heartbeat_interval) HEARTBEAT_INTERVAL = parseInt(options.heartbeat_interval)

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