如何调用队列触发功能?

问题描述 投票:0回答:1

我已经从模板创建了一个简单的触发器函数,如果我从 Visual Studio 进行调试,则效果非常好,即 一旦我手动将消息添加到队列中,我就可以在 Visual Studio 的调试输出中看到该消息。

因此,我计划将其发布到我的门户,现在,如果我将消息添加到队列中,我在 kudu 终端中看不到任何输出,也没有看到任何消息出队。

如何调用队列触发函数?

这是我的简单代码:

[Function(nameof(Function1))]
public string Run([QueueTrigger("sample", Connection = "ConnString")] QueueMessage message)
{
    _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}");
    return message.MessageText;
}

这是应用程序服务编辑器终端的输出

app service editor terminal

抱歉,如果这听起来很蹩脚,我是 Azure 的新手:)

提前非常感谢!

azure-functions message-queue azure-queues
1个回答
0
投票

您可以直接在Azure Function App中的Function的

Invocations
中看到日志。

部署完成后,请务必在功能应用 >

Environment variables
>
App settings
中添加队列连接,如下所示,

ConnString": "<storageConneString>

enter image description here

我已经在Azure存储队列中发送了一条消息,如下所示,

enter image description here

Azure 函数应用程序调用:

过了一段时间,我在

Invocations
下的Function中得到了日志,如下所示。

enter image description here

函数1.cs:

using Azure.Storage.Queues.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
 
namespace FunctionApp8
{
    public class Function1
    {
        private readonly ILogger<Function1> _logger;
 
        public Function1(ILogger<Function1> logger)
        {
            _logger = logger;
        }
 
        [Function(nameof(Function1))]
        public void Run([QueueTrigger("sample", Connection = "ConnString")] QueueMessage message)
        {
            _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}");
        }
    }
}

local.settings.json:

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    "ConnString": "<storageConneString>"
  }
}
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.