loopback-component-nsq

Loopback Component for working with a NSQ

Usage no npm install needed!

<script type="module">
  import loopbackComponentNsq from 'https://cdn.skypack.dev/loopback-component-nsq';
</script>

README

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

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

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

 {
   "loopback-component-nsq": {
     "options": {
     }
   }
 }
  1. Configure the NSQ Data Source inside datasources.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