2.0.2 • Published 5 months ago
@evva/nest-mqtt v2.0.2
Nest MQTT
Install
npm i @evva/nest-mqtt
Description
Client implementation for an MQTT Broker that also supports shared subscriptions. Offers additional decorators to simply usage.
Build & Package
# Nest Build
$ nest build
Usage
Import the module wherever needed and inject the MqttService
into your service for use.
@Module({
imports: [MqttModule],
})
export class ExampleModule {
constructor(private readonly mqttService: MqttService) {}
public async example() {
try {
await this.mqttService.connect({
host: '127.0.0.1',
protocol: 'mqtt',
port: 1883,
username: 'test',
password: 'test',
autoSubscribe: true
})
} catch (e) {
console.log(`Failed to connect: ${e}`)
}
}
@Subscribe('exampleTopic')
public onExampleTopicEvent(@Payload() payload: object) {
console.log(payload)
}
}
Tip: Use the
autoSubscribe
flag to automatically subscribe to all @Subscribe() decorators.
Stay in touch
- Author - microud/nest-mqtt
- Author - sfw-e
License
Proprietary