nsq-publisher
v1.0.3
Published
Simple way to create topics and publish messages in NSQ
Downloads
15
Readme
NSQ Publisher
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));