2

In my scenario, I'm sending messages to a ServiceBus Queue. I have an azure function that is being triggered on that Queue. The function receives the message, checks status using some other API endpoint, if it's processed I send out an email. But when the processing of that request is not complete, I want to put the message on the queue (with some delay or scheduled time later in the future) so that function receives the same message again and checks again. The order doesn't necessary matter that much for me.

I have tried these approaches so far:

BrokeredMessage.Abandon() - which immediately triggers the function - not desirable behavior BrokeredMessage.Abandon() with ScheduledEnqueueTimeUtc property -- same behavior

BrokeredMessage.Defer() - here i need to keep track of message sequence number to receive the message using OnReceive - not convenient (or even possible within a function?)

Resending the same message to the queue with ScheduledEnqueueTimeUtc property set to later time - For this i need to get reference to the Queue Client again and send the message -- THIS sort of works but feels wrong (as i have to complete the actual message i received and dispatch another message from within the function).

Moreover, I've tried using WebJobs and Azure Storage Queue - pretty much same issues i encountered there.

Is there any better way to get this done? I'm open to use other approaches as well. I'm not sure if I can achieve something similar with LogicApp?

Thanks Sanjay

Sanjay Bhagia
  • 155
  • 12

1 Answers1

2

I think your best bet is to send a new message. For that, use an output binding and return an instance of BrokeredMessage with proper ScheduledEnqueueTimeUtc value. You can Clone the original message, if you get it as BrokeredMessage in your function. Propably, you will need to use ICollector for this output binding, since your output is conditional.

Functions runtime calls Complete/Abandon methods itself based on function execution result, so you can't do that manually inside the function. Defer-Receive combination isn't supported either.

The same approach should apply to Storage Queues.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • Thanks for the suggestion Mikhail. I'll try the output binding. – Sanjay Bhagia Nov 21 '17 at 21:25
  • It worked with ICollector (I used IAsyncCollector). Slightly better than creating queue client manually within the function. However, still it feels a hack. This should be quite a normal scenario and i was hoping that Function/webjob runtime would provide the support for this. – Sanjay Bhagia Nov 22 '17 at 09:58
  • 1
    Also remeber that the new message will have new DeliveryCount and TTL - it's good to set some custom 'MyDeliveryCount' property to increment it and check it on redelivery. – Dominik Minc Nov 21 '18 at 13:43
  • Has anything change on this front? I still didn't anything on this. looks like it's still the same way it was before. – Sanjay Bhagia Jun 08 '19 at 05:15