如何通过服务总线队列触发函数将服务总线队列消息移至死信
最佳答案
https://github.com/Azure/azure-webjobs-sdk/issues/1986#issuecomment-433960534
In v3, you can bind to the MessageReceiver class, which exposes methods like DeadLetter, Abaondon, Complete, etc. Example:
public static async Task ProcessMessage( [ServiceBusTrigger("myqueue")] string message, int deliveryCount, MessageReceiver messageReceiver, string lockToken) { . . . await messageReceiver.DeadLetterAsync(lockToken); . . . }
In this example, the message is bound as a string and the various message properties including lockToken are bound as params. You can also bind the message as a Message Type and access the requisite message properties from there. In v2 the ServiceBus SDK exposed these message methods directly on the BrokeredMessage class itself, but in the latest version of their SDK those methods no longer exist, meaning you have to bind to MessageReceiver to access them.
编辑时,您还需要将AutoComplete
设置为 false。 https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=csharp#configuration
关于azure - 如何在服务总线队列触发函数中将服务总线消息移至死信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61191322/