Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 3 Examples of "nsqjs in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'nsqjs' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

function consume(subject, channel, reply) {
    const readerKey = `${subject}.${channel}`

    // only one reader per topic channel combination
    if (readers.has(readerKey)) {
      return reply()
    }

    // if not exist, create Reader instance
    const reader = new Nsq.Reader(subject, channel, opts.nsqReader)

    reader.connect()

    reader.on(Nsq.Reader.NSQD_CONNECTED, (host, port) => {
      hemera.log.info('NSQ Reader connected to %s:%s', host, port)
      reply()
    })

    reader.on(Nsq.Reader.DISCARD, msg => {
      hemera.log.warn(msg, 'NSQ Message was discarded')
    })

    reader.on(Nsq.Reader.ERROR, err => {
      hemera.log.error(err, 'NSQ Reader error')
      reply(err)
      // Let it crash and restart
},
        err => {
          if (!err) {
            return msg.finish()
          }

          msg.requeue()
        }
      )
    })

    readers.set(readerKey, reader)
  }

  // only one writer for this service
  const writer = new Nsq.Writer(
    opts.nsqWriter.host,
    opts.nsqWriter.port,
    opts.nsqWriter.options
  )

  writer.connect()

  writer.on('error', err => {
    hemera.log.error(err, 'NSQ Writer error')
    hemera.fatal() // Let it crash and restart
  })

  writer.on('closed', () => {
    hemera.log.warn('NSQ Writer closed')
  })
OutputNsq.prototype.start = function(callback) {

  if (!this.topic||!this.dataUrl) { logger.error('Critical Error! Missing config!'); return; }
  logger.info('Initializing NSQ Publisher...');

  const w = new nsq.Writer(this.dataUrl, this.dataTcpPort);
  var count = 0;

  w.connect();
  w.on('ready', () => {
    logger.info('NSQ Writer Ready!');
    this.nsqw = w;
  });

  w.on('closed', () => {
    logger.error('NSQ Writer closed!');
    if (count < this.retries) {
	    logger.info('Reconnecting in '+this.timeout+'');
	    setTimeout(function(){ w.connect(); }, this.timeout);
    } else {
	logger.error('Giving up! Attempted:',this.retries);
   }

Is your System Free of Underlying Vulnerabilities?
Find Out Now