{"_id":"@bucai/nest-mqtt","name":"@bucai/nest-mqtt","dist-tags":{"latest":"1.0.6"},"versions":{"1.0.6":{"name":"@bucai/nest-mqtt","version":"1.0.6","description":"A MQTT module for Nest.js","author":{"name":"microud,fetaoily,cvidlmx"},"license":"MIT","main":"dist/index.js","types":"dist/index.d.ts","repository":{"url":"git+https://github.com/cvidlmx/nest-mqtt.git"},"keywords":["nest-mqtt","nestjs-mqtt","@nestjs/mqtt","mqtt","nestjs"],"scripts":{"build":"rimraf dist && tsc -p tsconfig.build.json","format":"prettier --write \"src/**/*.ts\"","lint":"tslint -p tsconfig.json -c tslint.json","publish":"npm run build && npm publish --access=public"},"peerDependencies":{"@nestjs/common":"^6.10.11 || ^7.0.0 || ^8.0.0 || ^10.0.0","@nestjs/core":"^6.10.11 || ^7.0.0 || ^8.0.0 || ^10.0.0","mqtt":"^5.0.5"},"devDependencies":{"@nestjs/common":"10.2.5","@nestjs/core":"10.2.5","@types/mqtt":"2.5.0","@types/node":"20.6.3","prettier":"3.0.3","reflect-metadata":"0.1.13","rimraf":"5.0.1","rxjs":"7.8.1","ts-node":"10.9.1","tsc-watch":"6.0.4","tsconfig-paths":"4.2.0","tslint":"6.1.3","typescript":"5.2.2"},"_id":"@bucai/nest-mqtt@1.0.6","gitHead":"0cb3ac7568f8fcf04162e15cc0d0f4e39f6303c6","bugs":{"url":"https://github.com/cvidlmx/nest-mqtt/issues"},"homepage":"https://github.com/cvidlmx/nest-mqtt#readme","_nodeVersion":"18.19.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-9UB/1gLI28IaLS5IE8aLfKqVFOoDV0kGtfBeuqVBuyy0Ebbd34dvGi0MLPkDFYNBHSzxheXjuHAmFv7caq+ZHw==","shasum":"4afc33cfc6d1cf9b821b79a7bcd41ed59fb7bafd","tarball":"https://registry.npmjs.org/@bucai/nest-mqtt/-/nest-mqtt-1.0.6.tgz","fileCount":34,"unpackedSize":141126,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA4STWOBTJKYDiaUm+dhN+WfAlZzK1M/HH/nyS+NnOZHAiA0CcXggHTlFAnadb0UwOkF/3JJdfbdwBVxNXe0BlanSQ=="}]},"_npmUser":{"name":"notbucai","email":"1450941858@qq.com"},"directories":{},"maintainers":[{"name":"notbucai","email":"1450941858@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nest-mqtt_1.0.6_1723626241168_0.6060378591720568"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-14T09:04:01.087Z","1.0.6":"2024-08-14T09:04:01.331Z","modified":"2024-08-14T09:04:01.580Z"},"maintainers":[{"name":"notbucai","email":"1450941858@qq.com"}],"description":"A MQTT module for Nest.js","homepage":"https://github.com/cvidlmx/nest-mqtt#readme","keywords":["nest-mqtt","nestjs-mqtt","@nestjs/mqtt","mqtt","nestjs"],"repository":{"url":"git+https://github.com/cvidlmx/nest-mqtt.git"},"author":{"name":"microud,fetaoily,cvidlmx"},"bugs":{"url":"https://github.com/cvidlmx/nest-mqtt/issues"},"license":"MIT","readme":"# Nest-MQTT\n\n## Description\n\nA MQTT module for Nest.js. Compatible with emqtt.\n\n## Installation\n\n```bash\n$ npm install @cvidlmx/nest-mqtt mqtt --save\n```\n\nor\n```bash\n$ yarn add @cvidlmx/nest-mqtt mqtt\n```\n\n## Usage\n\n### Import\n\nNest-mqtt will register as a global module.\n\nYou can import with configuration\n\n```typescript\n// app.module.ts\nimport {Module} from '@nestjs/common';\nimport {MqttModule} from '@fetaoily/nest-mqtt';\n\n@Module({\n  imports: [MqttModule.forRoot(options)]\n})\nexport class AppModule {\n}\n```\n\nor use async import method\n\n```typescript\n// app.module.ts\nimport {Module} from '@nestjs/common';\nimport {MqttModule} from '@fetaoily/nest-mqtt';\n\n@Module({\n  imports: [MqttModule.forRootAsync({\n    useFactory: () => options,\n  })]\n})\nexport class AppModule {\n}\n```\n\n### Subscribe\n\nYou can define any subscriber or consumer in any provider. For example,\n\n```typescript\nimport {Injectable} from '@nestjs/common';\nimport {Subscribe, Payload, Topic} from '@fetaoily/nest-mqtt';\n\n@Injectable()\nexport class TestService {\n  @Subscribe('test')\n  test() {\n\n  }\n\n  @Subscribe({\n    topic: 'test2',\n    transform: payload => payload.toString(),\n  })\n  test2() {\n\n  }\n}\n```\n\nAlso, you can inject parameter with decorator:\n\n```typescript\nimport {Injectable} from '@nestjs/common';\nimport {Subscribe, Payload} from '@fetaoily/nest-mqtt';\n\n@Injectable()\nexport class TestService {\n  @Subscribe('test')\n  test(@Payload() payload) {\n    console.log(payload);\n  }\n}\n```\n\nHere are all supported parameter decorators:\n\n#### Payload(transform?: (payload) => any)\n\nGet the payload data of incoming message. You can pass in a transform function for converting.\n\n#### Topic()\n\nGet the topic of incoming message.\n\n#### Packet()\n\nGet the raw packet of incoming message.\n\n#### Params()\n\nGet the wildcard part of topic. It will return an array of string which extract from topic. For example:\n\nWhen subscribe the topic \"test/+/test/+\" and incoming topic is \"test/1/test/2\", you will get the array `[\"1\", \"2\"]`.\n\n### Publish\n\nNest-mqtt wrap some functions with `Promise` and provide a provider.\n\n```typescript\nimport {Inject, Injectable} from '@nestjs/common';\nimport {MqttService} from '@fetaoily/nest-mqtt';\n\n@Injectable()\nexport class TestService {\n  constructor(\n    @Inject(MqttService) private readonly mqttService: MqttService,\n  ) {\n  }\n\n  async testPublish() {\n    this.mqttService.publish('topic', {\n      foo: 'bar'\n    });\n  }\n\n}\n```\n\n## Emqtt Compatible\n\nnest-mqtt support emq shared subscription\n\n- Global mode\n\nModule options support queue and share property for globally converting all topic to shared topic except configured in\nsubscription options.\n\n```typescript\n// app.module.ts\nimport {Module} from '@nestjs/common';\nimport {MqttModule} from '@fetaoily/nest-mqtt';\n\n@Module({\n  imports: [MqttModule.forRoot({\n    host: '127.0.0.1',\n    queue: true,\n    share: 'group1'\n  })]\n})\nexport class AppModule {\n}\n```\n\n- Configure in Subscribe\n\n```typescript\nimport {Injectable} from '@nestjs/common';\nimport {Subscribe, Payload, Topic} from '@fetaoily/nest-mqtt';\n\n@Injectable()\nexport class TestService {\n  @Subscribe('test')\n  test() {\n\n  }\n\n  @Subscribe({\n    topic: 'test2',\n    queue: true,\n  })\n  test2() {\n\n  }\n}\n```\n\nThe priority of subscribe is higher than the global mode. If you want to specify a topic do not use the shared mode, set\nit as false in subscribe decorator.\n\n## Support\n\nNest-mqtt is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers.\nIf you'd like to join them, please [read more here](https://docs.nestjs.com/support).\n\n## Stay in touch\n\n- Author - [microud](https://xknow.net)\n\n## License\n\nnest-mqtt is [MIT licensed](LICENSE).\n","readmeFilename":"README.md"}