天蓝色队列中的消息消失

问题描述

我希望这里的人能对我现在遇到过两次的问题有所帮助。 我有一个在其中创建发票的ERP系统,当准备好发送这些发票时,便可以通过cron计划的作业将它们转移到我们的发票系统中。当它们从发票系统发送给最终客户时,它会触发webhook到azure http触发函数,该函数将消息(invoiceId)放入队列中。然后,我有一个队列触发器,可以接管这些触发器并更新我们的ERP系统,以便不再更改发票。 90%的时间都可以正常工作。

上周,我们向发票系统发送了12张发票,簿记员将这些发票发送给了客户。 当今天早上检查时,其中的2个在我们的ERP系统中未更新为“已发送”状态。 因此,我检查了队列触发器,可以看到有问题的两个发票没有被调用(在功能->监视器下)。因此,我检查了中毒队列,该队列也不存在,也没有出现在实际队列中。最后,我检查了Http触发器调用,发现有两个发票正在调用中,并且在日志中将消息放入已正确记录且没有错误的消息附近。

所以让我感到奇怪的是,对于其他10张发票,这很好,没有丢失任何东西。但是对于这两个队列消息似乎消失了。有人有什么想法吗?

共享我的两个功能添加到队列和更新我们的ERP系统。

HttpTrigger

[FunctionName(nameof(InvoiceBooked))]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous,"post",Route = null)]
            HttpRequest req,ILogger log)
        {
            try
            {
                log.Loginformation("Invoice Booked from VS. C# HTTP trigger function processed a request.");
                string invoiceBookedId = req.Query["invoiceId"];
                log.Loginformation($"Invoice Booked. RequestBody: {invoiceBookedId}");

                if (string.IsNullOrEmpty(invoiceBookedId))
                {
                    log.LogError("Invoice Booked. Query was empty");
                    return new BadRequestResult();
                }

                // Get the connection string from app settings
                var storageAccountName = System.Environment.GetEnvironmentvariable("StorageAccountName",EnvironmentvariableTarget.Process);
                var storageAccountKey = System.Environment.GetEnvironmentvariable("StorageAccountKey",EnvironmentvariableTarget.Process);
                string connectionString =
                    $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey};EndpointSuffix=core.windows.net";

                // Instantiate a QueueClient which will be used to create and manipulate the queue
                var queueClient = new QueueClient(connectionString,AzureConstants.InvoiceBookedQueueName);

                // Create the queue
                await queueClient.CreateIfNotExistsAsync();
                log.Loginformation($"Invoice Booked. Enqueuing message: {invoiceBookedId}");
                if (await queueClient.ExistsAsync())
                {
                    var messageBase64 = System.Convert.ToBase64String(
                        System.Text.Encoding.UTF8.GetBytes(invoiceBookedId));

                    // Send a message to the queue
                    await queueClient.SendMessageAsync(messageBase64);

                    log.Loginformation($"Invoice Booked. Message enqueued: {invoiceBookedId}");
                }
            }
            catch (Exception e)
            {
                log.LogError(e,"Invoice Booked. Error when enqueueing booked invoice");
            }

            return (ActionResult)new OkResult();
        }

队列触发器

[FunctionName(nameof(InvoiceBookedQueueTrigger))]
        public static void Run([QueueTrigger(AzureConstants.InvoiceBookedQueueName,Connection = "QueueStorage")]string queueItem,ILogger log)
        {
            log.Loginformation($"InvoiceBookedQueueTrigger. C# Queue trigger function processed: {queueItem}");

            var erpService = new ERPService(log,System.Environment.GetEnvironmentvariable("APIKey",EnvironmentvariableTarget.Process));

            int.TryParse(queueItem,out var invoiceId);

            log.Loginformation($"invoiceId is: {invoiceId}");

            var success = erpService.SetInvoiceBooked(invoiceId);

            if(!success)
                throw new WebException("There was a problem updating the invoice in erp");
            
        }

我似乎发现了一些其他信息。由于某些原因,作业主持人有时会停止。今天我注意到,在我手动输入一些消失的ID的过程中,有些经历了,但又一次消失了。在跟踪日志中,我可以看到在应该获取队列项目的那一刻,作业主机已停止。使我感到奇怪的是,该消息已出队,根本没有关于此的日志记录。如果我在启动消息时将其放入队列中,则一切正常。任何人有任何想法吗?我已经添加了日志供您浏览

可以在此处下载日志文件https://1drv.ms/t/s!AotNYJ6EYJBWiRysY93fP2ODdFVX

解决方法

与 Microsoft 支持一起,我发现在使用消耗计划时,存在可能会以某种方式丢失队列项目的问题。 MS 支持人员无法解释该问题,但更改为应用服务计划已完全解决了该问题。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...