nsq-publisher

1.0.3 • Public • Published

NSQ Publisher

Build Status Coverage Status Dependency Status

Simple way to create topics and publish messages.

Installation

npm instal --save nsq-publisher

Usage

const Publisher = require('nsq-publisher');
 
 
const pub = new Publisher({
  dataUrl: 'localhost', // optional 
  dataHttpPort: 4151, // optional 
  dataTcpPort: 4150, // optional 
  topic: 'test-topic', 
  protocol: 'http', // optional 
  autoCreate: false // optional
});
 
 
 
 
// pub.createTopic is necessary to make sure that topic exists, 
// but is not necessary if autoCreate is set to true
pub.createTopic(function (err) {
  if (err) {
   console.error(err);
  } else {
   console.log('ok');
  }
});
// or
pub.createTopic()
  .then(() => console.log('ok'))
  .catch(err => console.error(err));
  
  
pub.publish('test message', function (err) {
  if (err) {
   console.error(err);
  } else {
   console.log('published');
  }
});
 
// or
 
pub.publish('test message')
  .then(() => console.log('published'))
  .catch(err => console.error(err));
 

Readme

Keywords

Package Sidebar

Install

npm i nsq-publisher

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • menoncello