0
votes

I am using Azure Service Bus REST API to receive messages. The requirement is to have a scheduled job to read messages from Azure Service Bus Queues and forward them for processing. If processed successfully, then delete them from the Queue or keep them in the Queue to be processed in the next scheduled job. I am using Peek-Lock Message (Non-Destructive Read) method(https://docs.microsoft.com/en-us/rest/api/servicebus/peek-lock-message-non-destructive-read).

The problem i am facing is inside my loop, how to know that i have read the queue fully so that i do not re-read the same queue again.

1

1 Answers

0
votes

Your requirement is somewhat problematic.

If processed successfully, then delete them from the Queue or keep them in the Queue to be processed in the next scheduled job.

Successful processing should always result in message completion. Otherwise, you're asking for trouble. When processing messages in peek-lock mode, the message is locked for up to 5 minutes. It's your responsibility to complete it if the processing is successful. If it wasn't completed, that's a sign the processing wasn't successful and it should be read again given your requirement. Do not leave successfully processed messages in the queue.

The problem i am facing is inside my loop, how to know that i have read the queue fully so that i do not re-read the same queue again.

You shouldn't be concerned about this. Read messages and process. If failed to process, the message will reappear. Otherwise, a message should be removed. If you want to handle idempotency, i.e. ensure that if for some reason the message is not processed more than once, upon successful processing and prior to completion store the message ID (assuming it's unique) in a data store and validate any new message against that data store.