IMessageReceiver

Callback interface to receive incoming messages.

Description

The IMessageReceive interface is used to receive incoming messages.

Instance methods

receiveMessage

Receives an incoming message from the queue.

See also MessageEnvelope, IMessageQueue

receiveMessage(envelope: MessageEnvelope, queue: IMessageQueue): Promise<void>

Examples

import { IMessageQueue, IMessageReceiver, MemoryMessageQueue, MessageEnvelope } from "pip-services3-messaging-nodex";

export async function main() {
   
    let messageQueue = new MemoryMessageQueue();
    messageQueue.listen("123", new MyMessageReceiver());

    await messageQueue.open("123")
    await messageQueue.send("123", new MessageEnvelope(null, "mymessage", "ABC")); // Output in console: "ABC"
}

class MyMessageReceiver implements IMessageReceiver {
    public async receiveMessage(envelop: MessageEnvelope, queue: IMessageQueue): Promise<void> {
        console.log("Received message: " + envelop.getMessageAsString());
    }
}