【问题标题】:Azure Function Isolated with QueueOutput and InitialVisibilityDelay使用 QueueOutput 和 InitialVisibilityDelay 隔离的 Azure 函数
【发布时间】:2022-11-13 12:35:34
【问题描述】:

之前孤立Azure Functions,可以创建一个输出绑定队列像这样: [Queue(...)] CloudQueue outputQueue

然后,我们可以添加一条能够添加可见性延迟的新消息,如下所示:

var cloudQueueMessage = new CloudQueueMessage("some message");
var timespan = new TimeSpan(0, 10, 0);

outputQueue.AddMessage(cloudQueueMessage, initialVisibilityDelay: timespan);

现在我们已经将这些 Azure Function 迁移到孤立模式,如何为消息添加可见性延迟?

这是微软网站上的一个例子

我们如何使用孤立模式

谢谢

【问题讨论】:

    标签: azure-functions azure-functions-isolated


    【解决方案1】:
    • await Task.Delay(n)(模拟消息处理的任务延迟)在隔离 Azure Functions C# 项目中为我工作,以延迟消息的可见性。
         [Function("Function1")]
            public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
            {
                _logger.LogInformation("C# HTTP trigger function processed a request.");
    
                var response = req.CreateResponse(HttpStatusCode.OK);
                response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
    
                response.WriteString("Welcome to Azure Functions!");           
                for (var i = 0; i < 5; i++)
                {
                    _logger.LogInformation($"Next visible {i}: {response.ToString()}");
                    await Task.Delay(1000);
                }
                return response;
    
            }
    

    结果:

    【讨论】:

      猜你喜欢
      • 2021-08-31
      • 2022-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多