Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Service Bus Queue: Can I manage/cancel scheduled messages?

If I schedule a message in the future using something like this:

d = datetime.utcnow() + timedelta(minutes=5)
task = {"some": "object"}

sbs.send_queue_message(
    qn,
    Message(
        task, 
        broker_properties={'ScheduledEnqueueTimeUtc': d}
    )
)

Then is there a way that I can view/delete messages that have been scheduled? send_queue_message doesn't return anything, and receive_queue_message understandably doesn't return items that are scheduled to be queued later - so I can't get hold of it to pass to delete_queue_message for example.

The Azure team seem aware of the usecase because Storage Queues seem to have something like this feature: https://azure.microsoft.com/en-gb/blog/azure-storage-queues-new-feature-pop-receipt-on-add-message/

Basically I need to be able to schedule a message to be queued later, but have this cancelable. Ideally I'd like to be able to also view all future scheduled tasks, but being able to just store an id that can be used to later delete the queued message would be sufficient.

The Azure UI shows the count of active/scheduled messages too, which seems to suggest there should be some way to see those scheduled ones!

Would queue storage be better for this? Or does service bus have some approach that might work? ScheduledEnqueueTimeUtc seems more flexible than the visibility timeout in queue storage so it'd be nice to stick with it if I can.

like image 879
Callum M Avatar asked Mar 06 '23 10:03

Callum M


1 Answers

Yes, it's possible.

Don't know if NodeJS client has support for it or not, but with C# client there's an alternative to ScheduledEnqueueTimeUtc approach I've described here. Using QueueClient.ScheduleMessageAsync() you can send a scheduled message and get the SequenceNumber. Which then can be used to cancel the message at any point in time using QueueClient.CancelScheduledMessageAsync(sequenceNumber).

like image 89
Sean Feldman Avatar answered Mar 28 '23 01:03

Sean Feldman