Skip to content

Subscribe General Message

Jefferson Medeiros edited this page Apr 28, 2020 · 3 revisions

Parameters:

  • routingKey: string - Defines the rule that will be used by the exchange to perform message routing;
  • callback: (message: any) => void - Function that will be executed when a message is directed by the exchange to the current subscribe;

Return:

  • Promise<void> - 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 events not mapped on the event bus
sub(routingKey: string, callback: (message: any) => void): Promise<void>

Example of use:

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

const ocariot: IOcariotRabbitMQClient = new OcariotRabbitMQClient("Target Microservice Name")

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

ocariot.sub("routkey.message", subCallback)

Clone this wiki locally