我正在编写一个Azure函数来获取Azure服务总线中的消息。
我希望手动处理任何异常("autoCompleteMessages": false
)
无法确定如何将完成或放弃发送回服务队列。
已尝试选项1:
[FunctionName("SBQ_F1_VC")]
public static async Task Run([ServiceBusTrigger("sbqfn1", Connection = "BrnlTest1_SERVICEBUS")]
ServiceBusReceivedMessage msg, ILogger log)
{
//.....
if(!Int32.TryParse(msg.ApplicationProperties.GetValueOrDefault("vid").ToString(), out vid))
{ await using ServiceBusclient client = new ServiceBusClient(Environment.GetEnvironmentVariable("BrnlTest1_SERVICEBUS"));
ServiceBusReceiver msgRcvr = client.CreateReceiver(Environment.GetEnvironmentVariable("queueName"), new ServiceBusReceiverOptions());
//await msgRcvr.RenewMessageLockAsync(msg);
await msgRcvr.AbandonMessageAsync(msg); //vid = 0;
}
//.....
}
错误选项1
System.Private.CoreLib: Exception while executing function: SBQ_F1_VC. Azure.Messaging.ServiceBus: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance. (MessageLockLost).
已尝试选项2:
[FunctionName("SBQ_F1_VC")]
public static async Task Run([ServiceBusTrigger("sbqfn1", Connection = "BrnlTest1_SERVICEBUS")]
ServiceBusReceivedMessage[] msgs,
ServiceBusMessageActions msgActions)
{
//.....
await msgActions.DeadLetterMessageAsync(msg);
}
错误选项2:
Microsoft.Azure.WebJobs.Host: Error indexing method 'SBQ_F1_VC'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'msgActions' to type ServiceBusMessageActions. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
备注:
Azure.Messaging.ServiceBus
命名空间
ServiceBusReceivedMessage
ServiceBusMessageActions
的参数名称必须为messageActions
。
出于某些原因,不允许更改此名称...
public static async Task Run(
[ServiceBusTrigger("sbqfn1", Connection = "BrnlTest1_SERVICEBUS")]
ServiceBusReceivedMessage[] msgs,
ServiceBusMessageActions messageActions)
{
您需要使用";MessageActions";作为参数名称,而不是";msgActions";。
这篇关于如何使用Azure服务总线5.0.0在C#azure函数中手动处理消息完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持吉威生活!
[英文标题]How to manually handle message completion in C# azure function with azure service bus 5.0.0
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。