azure - Web App后台任务的暂存槽处理消息

标签 azure azure-functions azure-web-app-service azure-deployment-slots

我正在使用 Azure 应用程序服务计划来托管处理服务总线主题消息的 Web 应用程序。 我正在使用 Azure Function App,它也具有 http 触发器来执行事件网格数据。 Web App(应用服务计划)和 Function App(Elastic Premium 计划)在生产中都有暂存槽。

在交换插槽时,我观察到 Web 应用程序的 stgaing 插槽正在处理消息。这是预期的行为吗? 对于功能应用程序暂存槽,我没有观察到这种行为。为什么会这样?

最佳答案

在每个插槽中添加一个名为“IsStaging”的应用程序设置,其中包含 true 和 false 值,然后当应用程序服务预热(启动或使用消息的方法)时停止请求,以便不会从 Staging 插槽消耗消息。

                if (CurrentConfiguration.IsStaging)
                {
                   logger.LogWarn("Staging slot cannot consume messages");
                   return;
                }

WebJob 更新:

        static void Main(string[] args)
        {
            JobHost host = CreateJobHost();
            if (CurrentConfiguration.IsStaging)
            {
                host.Call(typeof(Program).GetMethod("DoStagingInfiniteLoop"));
            }
            else
            {
                host.Call(typeof(Program).GetMethod("ProcessQueue"));
            }
        }


        private static JobHost CreateJobHost()
        {
            JobHostConfiguration jobHostConfig = new JobHostConfiguration();
            jobHostConfig.DashboardConnectionString = "DashboardCS";
            jobHostConfig.StorageConnectionString = "StorageCS";

            var JobHost = new JobHost(jobHostConfig);
            return JobHost;
        }


        [NoAutomaticTrigger]
        public static void DoStagingInfiniteLoop(TextWriter logger, CancellationToken token)
        {
            const int LOOP_TRACE_INTERVAL = 10000;
            ProcessLogger.WriteTrace("This is a staging environment, waiting...");
            while (true)
            {
                Task.Delay(LOOP_TRACE_INTERVAL).Wait(token);
            }
        }

        [NoAutomaticTrigger]
        public static void ProcessQueue(TextWriter logger, CancellationToken token)
        {
            //Your processing code here
        }

关于azure - Web App后台任务的暂存槽处理消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66801456/

相关文章:

azure - 我一直收到用户登录失败的消息。 Azure SQL 中的错误 18456

Azure Function CosmosDBTrigger 不可扩展

python - Visual Studio Code 和 Azure 中的异步 python 函数

.net - Azure 对 .NET 4.8 的支持

azure - 在Azure逻辑应用程序中如何使用负载均衡器在两个逻辑应用程序之间进行负载均衡

node.js - 如何在 Node js中将消息发送到azure服务总线队列时指定内容类型为application/json?

asp.net-mvc - 将 ASP.NET 应用程序部署到 Azure Web 应用程序时出现 HTTP 500.79 错误/System.UriFormatException

azure - 应用服务 HTTP/2 不工作

asp.net - 无法正确添加服务引用

azure - 有没有办法增加 Azure 事件网格系统主题交付操作超时时间?