Azure Service Bus stream

Hampus Olsson 0 Reputation points
2024-11-25T10:04:55.5166667+00:00

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();
Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
653 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.