0

我有一个 Azure Function HTTP 触发器来监听 Twilio webhook。AF 正在执行一项高级服务计划。它以 6% 的相当高的比率(在成百上千的成功中)向 Twilio 返回间歇性 502 错误。我真的需要弄清楚为什么会发生这种情况,因为我们缺少重要数据。

这个触发器所做的只是将传入的 webhook 发送到服务总线并返回一个 OK...我在另一个 AF 中有另一个几乎相同的 http 触发器,它可以听到来自 SendGrid 的数百万次点击而没有失败。所以我很难弄清楚这里的问题是什么。感谢任何建议,如果有问题,请告诉我。

这是我的触发代码:

namespace TwilioWebhookListener
{
    public class ReplyListener
    {
        private readonly AppSettings _settings;
        IQueueClient queueClient;

        public ReplyListener(AppSettings appSettings)
        {
            _settings = appSettings;
        }

        [FunctionName("Twilio-Reply-Listener")]
        public async Task<HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "reply")] HttpRequest httpRequest, 
            ILogger log)
        {

            var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("", Encoding.Default, @"application/xml") };
            try
            {
                log.LogInformation($"Twilio webhook - replyListener started at: { DateTime.UtcNow}");

                string requestBody = await new StreamReader(httpRequest.Body).ReadToEndAsync();

                queueClient = new QueueClient(_settings.ServiceBusConnection, "twilio-webhook-reply-messages");
                await queueClient.SendAsync(new Message(Encoding.UTF8.GetBytes(requestBody)));

                return response;
            }
            catch (Exception e)
            {
                log.LogInformation($"{DateTime.Now} :: Exception: {e.Message}");

                return response;
            }
        }
    }
} 
4

0 回答 0