为什么serviceBus会多次触发相同的消息? 相同的触发器由服务总线上的相同消息执行:
[FunctionName("ProcessOrderFromServiceBusQueue")]
public static void RunQueueMessages(
[ServiceBusTrigger("orderqueue", Connection = "ServiceBusConnectionString")]
string myQueueItem,
int deliveryCount,
DateTime enqueuedTimeUtc,
string messageId,
long sequenceNumber,
TraceWriter log, ExecutionContext context)
{
log.Info($"C# ServiceBus Queue trigger function processed message: {myQueueItem}");
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
//var conn = config["ServiceBusConnectionString"];
//var queueName = config["QueueName"];
//var queueClient = new QueueClient(conn, queueName);
//queueClient.CompleteAsync()
log.Info($"Received Order: OrderId:{messageId} SequenceNumber:{sequenceNumber} Body:{myQueueItem}");
// Deserialize the message body
var order = JsonConvert.DeserializeObject<Order>(myQueueItem);
// Process the order
ProcessOrder(order, log, config);
log.Info($"C# ServiceBus queue trigger function processed message: {messageId}");
}
答案 0 :(得分:0)
很可能函数体在消息处理过程中抛出异常。函数App中止其处理,消息返回队列并立即再次调度,再次失败等等。
最后,它达到Max Delivery Count并停在死信队列中。
你能检查一下我的假设吗?例如。同时打印deliveryCount
,并检查DLQ中的内容。