0

I have an Azure function that is trigger from a Subscription to an Azure Service Bus Topic. The definition looks as follows:

    [Function("logactivity")]
    public async Task Run([ServiceBusTrigger("marketplaceactivity", "logactivity", Connection = "ServiceBusConnection")] string mySbMsg,
        FunctionContext functionContext)
    {

Within this function, I want to send a message to the DeadLetterQueue if it does not pass certain validation. I have seen various answers but I have not been able to find the correct way to do this from within an Azure function triggered by a subscription to a service bus topic. Some solutions have referenced a method on the message object that can send it to the DeadLetterQueue but in my case I don't get a reference to a message. I have also tried looking at the standard properties I get access to including the FunctionContext but again, I don't see a way to get the message to go to the DeadLetterQueue. I have also looked into the Object Explorer in Visual Studio searching for DeadLetterQueue and found a reference to using Azure.Messaging.ServiceBus.ServiceBusReceiver.DeadLetterMessageAsync but I cannot seem to find where I would get access to that function within my Azure Function.

Any ideas / suggests would be greatly appreciated.

George M Ceaser Jr
  • 1,497
  • 3
  • 23
  • 52

1 Answers1

1

You seem to use Isolated Worker Functions SDK. It doesn't support message dispositioning yet. Your best bet for now is to let the retries to be exhausted and the message will be dead-lettered automatically.

There's a public issue related to this topic you can subscribe to.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • Thanks for the information. Is there a way for me to communicate back to the subscription that the message was not processed and it is retried? I did not see that option either – George M Ceaser Jr Apr 18 '23 at 15:23
  • No, there's no such thing. You pull a message off a queue and complete, abandon, defer, or dead-letter. These are disposition actions. And for now not possible with that SDK. A queue/subscription has a maximum delivery count and once it's exceeded, the message is dead-lettered. – Sean Feldman Apr 18 '23 at 20:00
  • That is the problem - I am not using a queue retrieve per say. I don't have access to a "Message" object in my function code as far as I can tell so how do I abandon the messasge? Do I throw an exception? What can I do?? – George M Ceaser Jr Apr 18 '23 at 20:26
  • Yes, you can throw. The function will retry, and exhaust all delivery attempts, eventually dead-lettering the message. Until Functions SDK for Isolated Worker adds support for the SDK types, not much else you can do. – Sean Feldman Apr 18 '23 at 23:17