c# - Deleting a message from Azure Queue Service by value -
i'm using azure storage queue service track queue of long running jobs en-queued multiple disparate clients, have requirement remove messages queue if exist matching given criteria.
i realise anti-pattern queue, service provide functionality in addition simple queueing (such delete message
, peek messages
) thought i'd try implement it.
the solution i've come works, not elegant , quite inefficient - , i'm wondering if can done better - or if should bin whole approach , use mechanism supports requirement design (which require fair amount of work across different systems). here simplified code:
var queue = methodthatgetstheappropriatequeuereference(); await queue.fetchattributesasync(); //populates current queue length if (queue.approximatemessagecount.hasvalue) { // messages , find messages removed. // makes messages unavailable other clients // visibilitytimeout period. // i've set minimum of 1 second - not ideal though var messages = await queue.getmessagesasync(queue.approximatemessagecount.value); var messagestodelete = messages.where(x => x.asstring.contains(someguid)); // delete applicable messages messagestodelete.tolist().foreach(x => queue.deletemessageasync(x)); }
note tried using peekmessagesasync()
avoid affecting messages not need deleted, not give popreceipt
required deletemessageasync()
.
the questions:
- is there way without pulling all of messages down? (there quite few)
- if 1 isnt possible, there way
popreceipt
message if usepeekmessagesasync()
?
is there way without pulling of messages down? (there quite few)
unfortunately no. have get
messages (a maximum of 32 @ time) , analyze contents of messages determine if message should deleted.
if 1 isnt possible, there way popreceipt message if use peekmessagesasync()?
again, no. in order popreceipt
, message must dequeued possible via getmessagesasync()
. peekmessagesasync()
returns message without altering visibility.
possible solution
you may want service bus topics , subscriptions
kind of functionality.
what create topic
messages sent.
then create 2 subscriptions
: in 1 subscription set rule checks message contents matching value , in other subscription set rule checks message contents not matching value.
what azure service bus check each message arrives against rules , accordingly pushes message in appropriate subscription. way have nice separation of messages should/shouldn't deleted.
Comments
Post a Comment