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
Microsoft.Azure.WebJobs.ServiceBus
命名空间中的ServiceBusMessageActions
类。它看起来像这样:
[FunctionName("MyFunction")]
public static async Task Run(
[ServiceBusTrigger("myQueue", Connection = "myConnection")]
ServiceBusReceivedMessage message,
ServiceBusMessageActions messageActions)
{
...
await messageActions.DeadLetterMessageAsync(message);
...
}
Microsoft.Azure.WebJobs.Extensions.ServiceBus
。MaxDeliveryCount
属性设置为1
,然后在函数触发时立即抛出异常。这样,消息的传递次数将增加1次,Service Bus会自动将该消息死信化。通过在Azure门户中创建Azure函数触发器来读取死信队列消息。在函数中,将DLQ的名称提供为“QueueName/$DeadLetterQueue”,如下图所示。
注意:如果您想访问主题中未投递的消息,则读取死信队列的语法应为“TopicName/Subscriptions/SubscriptionName/$DeadLetterQueue”。
现在,定义应该如何处理DLQ消息。在这里,如下面的截图所示,我们使用Azure Service Bus将“myqueue”的DLQ消息发送到名为“queue”的主题。
以这种方式,我们可以使用 Azure Functions 非常轻松地处理所需的 DLQ 消息。
Microsoft.Azure.WebJobs.Extensions.ServiceBus
包升级到4.3.0
。现在它完美地工作了,非常感谢。毫无疑问,这为我节省了数小时的搜索时间。 - Prolog