Skip to content

Subscribe Notification Message

Jefferson Medeiros edited this page May 8, 2020 · 1 revision

Table of Contents

Parameter:

  • callback: (message: any) => void - Function that will be executed when a message is directed by the exchange to the current subscribe;
  • The structure of the message that will be returned in the callback is as follows:
{
   event_name: string,
   timestamp: string,
   <resourceName>: object
}

Return:

  • Promise - Promise will not return anything if the subscription to the event was successful. In case of an error, an exception will be returned.
Method to subscribe in SendNotificationEvent.
subSendNotification(callback: (message: any) => void): Promise<void>

Example of use:

import { IOcariotRabbitMQClient, OcariotRabbitMQClient } from "@ocariot/rabbitmq-client-node"

const ocariot: IOcariotRabbitMQClient = new OcariotRabbitMQClient("notification.app")

function subCallback(message){
    console.log(message)
}

ocariot.subSendNotification(subCallback)

Message received (monitoring:miss_child_data notification)

{
    event_name: 'SendNotificationEvent',
    timestamp: '2020-05-08T11:37:10.017Z',
    notification: {
        notification_type: 'monitoring:miss_child_data',
        id: '5e98658864ec4852bb25c0f6',
        days_since: 11
    }
}

Message received (iot:miss_data notification)

{
    event_name: 'SendNotificationEvent',
    timestamp: '2020-05-08T11:42:40.033Z',
    notification: {
        notification_type: 'iot:miss_data',
        institution_id: '5a62be07de34500146d9c624',
        days_since: 15,
        sensor_type: 'humidity',
        location: {
            local: 'indoor',
            room: 'Bloco H sala 01'
        }
    }
}

Clone this wiki locally