2.1.6 • Published 6 years ago

hinos-mqtt v2.1.6

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

hinos-mqtt

A plugin helps to manage mqtt connection for hinos

Install

npm i hinos-mqtt -S

Examples

Typescript

Config mongo information

import { Mqtt } from 'hinos-mqtt';

Mqtt({
  url: 'mqtt://127.0.0.1',
  releaseTimeout: 60000,
  topic: {
    'API_RECEIVER': {
      des: 'Listen queue message for API',
      getListenerName: (_data: any) => `${AppConfig.mqtt.queue.API_RECEIVER}`,
      getError: (data: any) => !data.error ? null : data.error || 'Unknown'
    }
  }
}).debug(!Server.isProduction)
Mqtt({
    key: 'connection1',
    url: 'mqtt://192.168.0.56',
    topic: {
      'LOG_RECEIVER': {
        des: 'Listen queue message for Log realtime',
        getListenerName: (_data: any) => `${AppConfig.mqtt.queue.LOG_RECEIVER}`,
        getError: (data: any) => !data.error ? null : data.error || 'Unknown'
      }
    }
})

Use in service file

import { MQTT, Mqtt, MqttListener } from 'hinos-mqtt'

@MqttListener({
  des: 'Listen from queue mqtt',
  topic: 'LOG_RECEIVER'
  listenerName: AppConfig.mqtt.queue.API_RECEIVER,
  onHandler(err, data) {
    console.log(err, data)
  }
})
export class ChartService {
    @MQTT()
    static mqtt: Mqtt;
    
    @MQTT('connection1')
    static mqtt1: Mqtt;
    
    static async sendToMqtt(data: any = {}) {
        ChartService.mqtt.send('topic', data);
    }
}
2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.9

7 years ago

2.0.8

7 years ago

2.0.7

7 years ago

2.0.6

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago