Azure Service Bus stream
Hi,
I'm a bit confused on how to handle a stream for Azure Service Bus. I manage to connect, consume and complete messages.
Background:
The connection lasts 30 seconds and runs every 5 minutes. There are more messages on the queue than the program can consume in 30 seconds. Rising the timer would not help since it would need hours to consume all the messages. I have autoCompleteMessages set to false because if we fail I don't want to lose the message. Current program results in the message landing in the DLQ.
The problem:
The messages gets processed one after the other and will continue doing so until the time runs out. When the timer runs out the receiver and client are closed. If a message is currently being processed it won't be able to run completeMessage since the receiver is closed.
I've tried to keep track if a message is being processed, but even if I wait for it to be completed a new message will start being processed directly after it is completed. How am I supposed to stop consuming new messages when I want to close the connection and ?
receiver.subscribe({
processMessage: onMessage,
processError: onError,
}, {
autoCompleteMessages: false,
});
await delay(maxWaitTimeInMs);
await receiver.close();
await client.close();