'How to receive and handle messages from a Service Bus in a parallel mode using Node js
MS-(A) sends hundred of messages to a Azure service bus - topic, on the other side MS-(B) receives those messages by implementing AMQP subscribe
this.subscription = this.receiver.subscribe({
processMessage: this.onMessage,
processError: this.onError
});
async onMessage(message) {
await this.eventHandler(message)
}
public async eventHandler(message): Promise<void> {
console.log('before')
await Utilities.sleep(5000)
console.log('after')
}
The result is that the messages received in a sync mode instead of parallel. Meaning that till the handler not sends response, the other messages won't be received. I'd expect to read more messages till go to await.
current result: before (waiting for 5 sec) after
expected result: before before before ... after (after 5 sec)
How to implement it so messages keep received while the other are sleeping or in other words as a parallel mode?
Solution 1:[1]
I found that subscribe function can have options as a parameter.
subscribe(handlers: MessageHandlers, options?: SubscribeOptions): { close: any }
The object options of type SubscribeOptions contains prop maxConcurrentCalls which is enable to control the number of request to pull from a subscription.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | alonabr11 |
