npm i @evva/nest-mqtt
Client implementation for an MQTT Broker that also supports shared subscriptions. Offers additional decorators to simply usage.
# Nest Build
$ nest buildImport 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
autoSubscribeflag to automatically subscribe to all @Subscribe() decorators.
- Author - microud/nest-mqtt
- Author - sfw-e
Proprietary