How to use the zeromq.socket function in zeromq

To help you get started, we’ve selected a few zeromq 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 cyclux / tanglemonitor / backend / modules / ZMQ.js View on Github external
connect: (node, settings) => {
    if (zmqNodesAmountConnected < maxAmountZmqConnections) {
      zmqNodesAmountConnected++;

      zmqSockets[node.host] = zmq.socket('sub');
      zmqSockets[node.host].connect(`tcp://${node.host}:${node.port}`);
      console.log(
        Time.Stamp() +
          `Connected to ${node.host} | Current ZMQ node connections: ${zmqNodesAmountConnected}`
      );

      zmqSockets[node.host].subscribe('tx'); // New transactions
      zmqSockets[node.host].subscribe('sn'); // New confirmed transactions
      zmqSockets[node.host].subscribe('lmhs'); // New milestones

      zmqSockets[node.host].on('close', close => {
        zmqNodesAmountConnected--;
        console.log(
          Time.Stamp() +
            `Connection close: ${
              node.host
github bradyhouse / house / fiddles / node / fiddle-0037-ZmqPubSub / pub.js View on Github external
#!/usr/bin/env node --harmony
'use strict';

const fs = require('fs');
const zmq = require('zeromq');
const filename = process.argv[2];

// Create the publisher endpoint
const publisher = zmq.socket('pub');

fs.watch(filename, () => {
  // Send a message to any and all subscribers
  publisher.send(JSON.stringify({
    type: 'changed',
    file: filename,
    timestamp: Date.now()
  }));
});
// Listen on TCP port 60400
publisher.bind('tcp://*:60400', err => {
  if (err) {
    throw err;
  }
  console.log('Listening for zmq subscribers...');
});
github holochain / n3h / lib / ipc / client.js View on Github external
constructor (endpoint) {
    super()

    this.nextWaitingId = 0
    this.waiting = {}
    this.socket = zmq.socket('router')
    this.socket.on('message', (...args) => {
      this._handleMessage(...args)
    })
    this.socket.on('error', (...args) => {
      console.error(args)
      process.exit(1)
    })
    this.socket.connect(endpoint)

    this.startResolve = null
    this.startPromise = new Promise((resolve, reject) => {
      this.startResolve = resolve

      this.startPoll = setInterval(() => {
        this.ping()
      }, 100)
github pRizz / iota-transaction-stream / routes / iotaNodeListener.js View on Github external
function start() {
    console.log(`${new Date().toISOString()}: Connecting to ZMQ, ${zmqSource}`)

    if(iotaSocket) { stop() }

    iotaSocket = zmq.socket('sub')
    iotaSocket.connect(zmqSource)
    iotaSocket.subscribe('tx_trytes')

    iotaSocket.on('message', (topic, message) => {
        console.log(`${new Date().toISOString()}: Got message`)
        if(!topic) {
            return console.error(`${new Date().toISOString()}: Received message with no topic: ${topic}`)
        }

        const topicAsString = Buffer.from(topic).toString()

        console.log(`${new Date().toISOString()}: Got message: ${topicAsString.substring(0, 20)}`)

        const [_topic, trytes] = topicAsString.split(' ')
        const txObject = iota.utils.transactionObject(trytes)
        console.log(`${new Date().toISOString()}: got tx object from node`)
github holochain / n3h / packages / n3h-ipc / lib / client.js View on Github external
async init () {
    await super.init()
    this.$pushDestructor(() => {
      if (typeof this._stopHeartbeatTimers === 'function') {
        this._stopHeartbeatTimers()
        this._stopHeartbeatTimers = null
      }
      this._gotServerMessage = null
      this._socket.close()
      this._socket = null
    })

    this._connected = false
    this._socket = zmq.socket('router')
    this._socket.on('message', (...args) => {
      if (typeof this._gotServerMessage === 'function') {
        this._gotServerMessage()
      }
      this._handleMessage(...args)
    })
    this._socket.on('error', (...args) => {
      console.error(args)
      process.exit(1)
    })

    this._gotServerMessage = null
    this._stopHeartbeatTimers = null
  }
github hyperledger / sawtooth-core / sdk / javascript / messaging / stream.js View on Github external
connect (onConnectCb) {
    if (this._onConnectCb) {
      console.log(`Attempting to reconnect to ${this._url}`)
    }

    this._onConnectCb = onConnectCb

    this._futures = {}
    this._socket = zmq.socket('dealer')
    this._socket.setsockopt('identity', Buffer.from(uuid(), 'utf8'))
    this._socket.on('connect', () => {
      console.log(`Connected to ${this._url}`)
      onConnectCb()
    })
    this._socket.on('disconnect', (fd, endpoint) => this._handleDisconnect())
    this._socket.monitor(250, 0)
    this._socket.connect(this._url)

    this._initial_connection = false
  }
github bradyhouse / house / fiddles / node / fiddle-0038-ZmqReqRep / req.js View on Github external
'use strict';
const zmq = require('zeromq');
const filename = process.argv[2];
const requester = zmq.socket('req');
requester.on('message', data => {
    const response = JSON.parse(data);
    console.log('Received response: ', response);
});
requester.connect('tcp://127.0.0.1:60401');
console.log(`Sending a request for ${filename}`);
requester.send(JSON.stringify({path: filename}));
github iotaledger / industry-marketplace / YellowPages / server / src / services / zmqService.ts View on Github external
private connect() {
        try {
            if (!this._socket) {
                this._socket = zmq.socket('sub');
                this._socket.connect(this._config.zmq.endpoint);

                this._socket.on('message', (msg) => this.handleMessage(msg));

                const keys = Object.keys(this._subscriptions);
                for (let i = 0; i < keys.length; i++) {
                    this._socket.subscribe(keys[i]);
                }
            }
        } catch (err) {
            throw new Error(`Unable to connect to ZMQ.\n${err}`);
        }
    }
github iotaledger / industry-marketplace / ServiceApp / server / src / services / zmqService.ts View on Github external
private connect() {
        try {
            if (!this._socket) {
                this._socket = zmq.socket('sub');
                this._socket.connect(this._config.endpoint);

                this._socket.on('message', (msg) => this.handleMessage(msg));

                const keys = Object.keys(this._subscriptions);
                for (let i = 0; i < keys.length; i++) {
                    this._socket.subscribe(keys[i]);
                }
            }
        } catch (err) {
            throw new Error(`Unable to connect to ZMQ.\n${err}`);
        }
    }

zeromq

Next-generation ZeroMQ bindings for Node.js

MIT
Latest version published 12 days ago

Package Health Score

87 / 100
Full package analysis