1
votes

We are working on a scenario where user requests for generating some documents (through a web app) and these requests ( a message) are sent to azure service bus queue which when processed will result in generating a document.A user can make multiple requests for same document with updated data (which is part of the message) .What we need is that if there is a latest message from the user for the same document we take that message for generating document and other older messages can be ignored. User request can be identified using a unique identifier which potentially can be message id. Is there a way currently in azure service bus queues to implement this. To me this looks something exactly opposite of duplicate detection in queues.

1

1 Answers

1
votes

Technically, you can use Peek / PeekBatch methods to read the entire queue (on each receive of the document request message), and if a newer message with the same request / document is detected, skip the older (current) one. However depending on an average number of messages in your queue, this can be very inefficient. In my experience PeekBatch is somewhat fast (seconds, up to tens of seconds for hundreds messages) - but scanning the entire queue again and again does not feel right. Alternatively, if you can, instead of processing document requests right away. Persist the requests somewhere else externally, outside of ASB. Then periodically scan that table, and execute only the latest one, and purge the rest.