1.0.1 • Published 7 years ago

loopback-component-nsq v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

loopback-component-nsq

Loopback Component for working with a NSQ

Circle CI Dependencies Coverage Status

Installation

  1. Install in you loopback project:

    npm install --save loopback-component-nsq

  2. Create a component-config.json file in your server folder (if you don't already have one)

  3. Configure options inside component-config.json. (see configuration section)

     {
       "loopback-component-nsq": {
         "options": {
         }
       }
     }
4. Configure the NSQ Data Source inside `datasources.json`:

```json
  {
    "nsq": {
      "name": "nsq",
      "connector": "transient",
      "options": {
        "lookupdHTTPAddresses": ["127.0.0.1:4161"]
      }
    }
  }
  1. 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();
  }

};
  1. Publish a message
  app.models.NSQProducer.create({ topic: 'myTopic', body: { count, } })

License

MIT - Interactive Object https://interactive-object.com