loopback-component-nsq
v1.0.1
Published
Loopback Component for working with a NSQ
Downloads
3
Maintainers
Readme
loopback-component-nsq
Loopback Component for working with a NSQ
Installation
- Install in you loopback project:
npm install --save loopback-component-nsq
Create a
component-config.json
file in your server folder (if you don't already have one)Configure options inside
component-config.json
. (see configuration section)
{
"loopback-component-nsq": {
"options": {
}
}
}
- Configure the NSQ Data Source inside
datasources.json
:
{
"nsq": {
"name": "nsq",
"connector": "transient",
"options": {
"lookupdHTTPAddresses": ["127.0.0.1:4161"]
}
}
}
- User the build-in model
common/model/consumer.json
{
"name": "Consumer",
"base": "NSQConsumer",
"idInjection": true,
"options": {
"validateUpsert": true,
"nsq": {
"topic": "myTopic",
"channel": "myChannel"
}
},
"properties": {
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
module.exports = function(Consumer) {
// This is the method in which we handle the incoming message
Consumer.consume = function consume(msg) {
console.log(`Consumer: msg:`, msg.body.toString())
msg.finish();
}
};
- Publish a message
app.models.NSQProducer.create({ topic: 'myTopic', body: { count, } })
License
MIT - Interactive Object https://interactive-object.com