{"_id":"@anersonluisribeiro/dojot-module","_rev":"1-368e763fa2cbf43756506669da156d47","name":"@anersonluisribeiro/dojot-module","dist-tags":{"latest":"0.0.1-beta.8"},"versions":{"0.0.1-beta.8":{"name":"@anersonluisribeiro/dojot-module","version":"0.0.1-beta.8","description":"A library that provides utilities and methods for dojot","main":"index.js","scripts":{"test":"jest tests/unit-tests/*.test.js --coverage --report=html","test:watch":"jest --watch tests/unit-tests/*.test.js --coverage --report=html","mocks":"node ./tests/dojot-mock.js","sample":"node examples/sample.js","docs":"jsdoc -R ./README.md -p ./package.json -r -d ./docs --access all ./lib -c ./jsdoc.conf"},"repository":{"type":"git","url":"git+https://github.com/dojot/dojot-module-nodejs.git"},"keywords":["dojot","iot"],"author":{"name":"Muhamed Avila"},"bugs":{"url":"https://github.com/dojot/dojot-module-nodejs/issues"},"homepage":"https://github.com/dojot/dojot-module-nodejs/#readme","license":"GPL-3.0","dependencies":{"@dojot/dojot-module-logger":"0.0.1-alpha.5","axios":"^0.18.0","express":"^4.16.3","moment":"^2.22.2","node-rdkafka":"2.5.1","uuid":"^3.3.2"},"devDependencies":{"jest":"^24.1.0","assume":"^2.1.0","chai":"^4.1.2","chai-http":"^4.0.0","expect":"23.6.0","jsdoc":"3.5.5","mocha":"^5.2.0","sinon":"^6.1.4"},"jest":{"coverageDirectory":"./coverage/","collectCoverage":true,"collectCoverageFrom":["lib/**/*.js"]},"gitHead":"b4a7c1d3e5a93026dd33aceb8a67e5374da8a1bb","_id":"@anersonluisribeiro/dojot-module@0.0.1-beta.8","_npmVersion":"6.5.0","_nodeVersion":"11.9.0","_npmUser":{"name":"anersonluisribeiro","email":"anderson_lr@hotmail.com"},"dist":{"integrity":"sha512-mqbjxG1o8ZelaoS/mn+L3wkGYLlRjRTXMGbLDlaTNax9Xj3FQMaviM743srk6dO1v1WXNenKOQDdJQOYybWpEQ==","shasum":"979da696ad0800ac30efacf78f584148fb105242","tarball":"https://registry.npmjs.org/@anersonluisribeiro/dojot-module/-/dojot-module-0.0.1-beta.8.tgz","fileCount":21,"unpackedSize":156467,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeqIhxCRA9TVsSAnZWagAAxv0P/AzNwMzO9mBT3ucNFDxm\n6ya9sAEAAoNr0PUQnwOErQMw9LWYDvw6iD+qdIRejxgyEincnLc2BKPSxeew\nAw9n46nKQ3UIz6DK1MTnbGwSNLrKUfcABqNjjZJbTlQi3YeXgjysYeE3gs99\nIgE5RcvClvmxyI9FBpIfNRhGLW7B6Zv9kGnZif0xHQwj0jO2CFx35Z0ATMlY\nZ9LY2ltqIuIiNWr4m0OtRG7ksFv1RBArlbJqD1PSYIMvSIfzXFo6jQIm838M\nG0NSdjl4xBMNx1LvXwdHl2+k/Ga14D78ZTZaBzr/shJLw87lntjCqCgJWj9o\njNvarEzmymyJabBiOVndaYzE7YWs4oml/4tsB2/JH3gJie9tsMQA8Cxqwzwm\nomhRjWfdVppeug+fj0t0jzQfkwDpJ4NFaJCuxyWgZ/OyB+DhbSQEC+QjPYCQ\nEdDVFBw//KExjgtYe7XOf5H/OhrOZiAQ6qg3iEJTK553kIV8jDLGbyP23ItN\nSrpRFp0Y8bw9Om+tR/pul5Knw/dAnU/h06VgpOTIOYHApXrcMiMX2N6MM9K4\nDbnDgQWPgFkeDs5taET2GF5/bmxs5B1E14aY0pTCKgzZmBc4LAqBaTzIGRLD\nBVTgh8ICBQB0S5WCWdOVQLFPAdd7UvAIhWQC+27FhrPp5INMivWTJKF33R6n\ng+DF\r\n=oedY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCSh8lQBlB9JGY6bCOP1Rx3VDBMDavQm6aThA/Di+T0kwIgBld11YSIzBXJIrz0NI00E5ABnUzgHGmL69/BTaApFQ4="}]},"maintainers":[{"name":"anersonluisribeiro","email":"anderson_lr@hotmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dojot-module_0.0.1-beta.8_1588103280911_0.41975703663413144"},"_hasShrinkwrap":false}},"time":{"created":"2020-04-28T19:48:00.877Z","0.0.1-beta.8":"2020-04-28T19:48:01.025Z","modified":"2022-04-04T14:05:10.876Z"},"maintainers":[{"name":"anersonluisribeiro","email":"anderson_lr@hotmail.com"}],"description":"A library that provides utilities and methods for dojot","homepage":"https://github.com/dojot/dojot-module-nodejs/#readme","keywords":["dojot","iot"],"repository":{"type":"git","url":"git+https://github.com/dojot/dojot-module-nodejs.git"},"author":{"name":"Muhamed Avila"},"bugs":{"url":"https://github.com/dojot/dojot-module-nodejs/issues"},"license":"GPL-3.0","readme":"# dojot-module\n\n[![Build Status](https://travis-ci.com/giovannicuriel/dojot-module-nodejs.svg?branch=master)](https://travis-ci.com/giovannicuriel/dojot-module-nodejs)\n[![CodeFactor](https://www.codefactor.io/repository/github/dojot/dojot-module-nodejs/badge)](https://www.codefactor.io/repository/github/dojot/dojot-module-nodejs)\n[![DeepScan grade](https://deepscan.io/api/teams/2690/projects/3914/branches/33256/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=2690&pid=3914&bid=33256)\n[![codecov](https://codecov.io/gh/dojot/dojot-module-nodejs/branch/master/graph/badge.svg)](https://codecov.io/gh/dojot/dojot-module-nodejs)\n\nCommon library to be used in dojot modules.\n\n## Overview\n\nThis library is intended to handle all the necessary operations that a service\nneeds to perform in order to communicate with other dojot services. These\noperations are:\n\n- Sending and receiving messages via Kafka;\n- Subscribing to new Kafka topics whenever a new tenant is created;\n\nThus, the service should only inform the library of which subjects it is\ninterested in and how the messages should be processed.\n\n## How to install\n\nInstalling this package is no different than any other from npm. Just execute:\n\n```bash\n\nnpm install @dojot/dojot-module\n\n```\n\nwhich will install this module in its latest version.\n\n## How to use\n\nUsing it is also very easy. All normal operations involve using the Messenger\nclass, which is responsible for communicating with the message broker (Kafka)\nand generating events to any component interested in such messages. Also, it\nprovides a very simple mechanism of event generation and subscription so that\na library could use it to generate more specific events based on those messages.\nMore on that later.\n\nThe folowing code is an example of a code that simply prints any message that\nit receives from a particular subject.\n\n\n```javascript\n\"use strict\";\nvar dojot = require(\"@dojot/dojot-module\");\nvar logger = require(\"@dojot/dojot-module-logger\").logger;\n\nvar config = dojot.Config;\nvar messenger = new dojot.Messenger(\"dojot-snoop\", config);\nmessenger.init();\n\n// Create a channel using a default subject \"device-data\"\n// These \"communication channels\" will handle all the tenant processing and\n// message receival, so that the service implementation would only set the\n// message processing callback (done by 'messenger.on' calls).\n//\n// Creating a new channel will inform the library that the service is interested\n// in read/write messages to a particular subject.\nmessenger.createChannel(config.dojot.subjects.deviceData, \"rw\");\n\n// Create a channel using a particular subject \"service-status\"\nmessenger.createChannel(\"service-status\", \"w\");\n\n// Register callback to process incoming device data\nmessenger.on(config.dojot.subjects.deviceData, \"message\", (tenant, message, extraInfo) => {\n  logger.info(`Client: Received message in device data subject.`);\n  logger.info(`Client: Tenant is: ${tenant}`);\n  logger.info(`Client: Message is: ${message}`);\n  logger.info(`Client: ExtraInfo is: ${extraInfo}`);\n});\n\n// Publish a message on \"service-status\" subject using \"dojot-management\" tenant\nmessenger.publish(\"service-status\", config.management.tenant, \"service X is up\");\n\n```\n\n\n\n## Configuration\n\nThis library might be configured in different ways. Each class (Messenger,\nConsumer and Producer) receives a configuration object in its constructor. It\nshould have the following attributes at least:\n\n```json\n{\n  \"kafka\": {\n    \"producer\": {\n      \"metadata.brokers.list\": \"kafka:9092\",\n      \"socket.keepalive.enable\": true,\n      \"dr_cb\": true\n    },\n    \"consumer\": {\n      \"group.id\": \"sample-group\",\n      \"metadata.brokers.list\": \"kafka:9092\",\n    }\n  },\n  \"databroker\": {\n    \"url\": \"http://data-broker\",\n    \"timeoutSleep\": 2,\n    \"connectionRetries\": 5,\n  },\n  \"auth\": {\n    \"url\": \"http://auth:5000\",\n    \"timeoutSleep\": 5,\n    \"connectionRetries\": 5,\n  },\n  \"deviceManager\": {\n    \"url\": \"http://device-manager:5000\",\n    \"timeoutSleep\": 5,\n    \"connectionRetries\": 3,\n  },\n  \"dojot\": {\n    \"management\": {\n      \"user\": \"dojot-management\",\n      \"tenant\": \"dojot-management\"\n    },\n    \"subjects\": {\n      \"tenancy\": \"dojot.tenancy\",\n      \"devices\": \"dojot.device-manager.device\",\n      \"deviceData\": \"device-data\",\n    }\n  }\n}\n```\n\nAll these parameters can be found in [config.js](./lib/config.js) file. It is\nrecommended that the service implementation use this file as basis to configure\nother classes.\n\nThe Kafka section follows the parameters used by\n[node-rdkafka](https://github.com/Blizzard/node-rdkafka) library, which in turn\nfollows the configuration of\n[librdkafka](https://github.com/edenhill/librdkafka). These are the bare\nminumum that this library needs in order to operate correctly. All the values\nare the default ones, they might be changed depending on deployment scenario.\n\nThe config.js file will also get a few environment variables in order to ease\nconfiguration. They are:\n\n```bash\nexport KAFKA_HOSTS = \"kafka:9092\"\nexport KAFKA_GROUP_ID = \"dojot-module\"\nexport DATA_BROKER_URL = \"http://data-broker\"\nexport AUTH_URL = \"http://auth:5000\"\nexport DEVICE_MANAGER_URL = \"http://device-manager:5000\"\nexport DOJOT_MANAGEMENT_USER = \"dojot-management\"\nexport DOJOT_MANAGEMENT_TENANT = \"dojot-management\"\nexport DOJOT_SUBJECT_TENANCY = \"dojot.tenancy\"\nexport DOJOT_SUBJECT_DEVICES = \"dojot.device-manager.device\"\nexport DOJOT_SUBJECT_DEVICE_DATA = \"device-data\"\n```\n\n","readmeFilename":"README.md"}