Skip to content

Client implementation for an MQTT Broker that also supports shared subscriptions. Offers additional decorators to simply usage.

License

Notifications You must be signed in to change notification settings

evva-sfw/nest-mqtt

Repository files navigation

Nest MQTT

NPM Version NPM Downloads NPM Unpacked Size (with version) GitHub last commit GitHub branch check runs EVVA License

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

About

Client implementation for an MQTT Broker that also supports shared subscriptions. Offers additional decorators to simply usage.

Resources

License

Contributing

Stars

Watchers

Forks

Contributors