c# - Azure队列存储 Visual Studio 本地主机从QueueClient发送到毒队列的所有队列消息

标签 c# azure azure-functions azure-queues

我在 Visual Studio 中有 2 个项目,一个 Web API 和一个具有 Azure 队列存储触发器函数的 Azure 函数项目。我正在使用 Azure 存储模拟器。两者都使用 UseUseDevelopmentStorage=true 作为连接字符串。队列客户端正在接收 201,我在存储模拟器中看到该消息。但触发函数永远不会被触发。我没有看到任何控制台错误。但是,如果我使用存储模拟器添加消息,则会触发触发器。 所以触发功能确实可以工作,但只能通过模拟器。 QueueClient 代码正在运行,我收到 201 并在模拟器中看到该消息。 我在本地完成这一切,我还没有在 Azure 中创建队列。我不明白这怎么会成为一个问题,但我想我应该补充一点。

我的队列客户端代码是

    public async Task InsertCustomer()
    {
        var queueClient = new QueueClient(_configuration["StorageConnectionString"], "customer-items");
        var myString = "Testing";
        byte[] bytes = Encoding.Default.GetBytes(myString);
        myString = Encoding.UTF8.GetString(bytes);
        await queueClient.CreateIfNotExistsAsync();
        //just here for debugging
        var result = await queueClient.SendMessageAsync(myString);
    }

URI 正在将其发送到 http://127.0.0.1:10001/devstoreaccount1/customer-items

队列触发器是

public static class InsertCustomerQueue
{
    [FunctionName("InsertCustomer")]
    public static void Run([QueueTrigger("customer-items", Connection = "AzureWebJobsStorage")] string myQueueItem, ILogger log)
    {
        try
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
        }
        catch (Exception ex)
        {
            log.LogInformation(ex.ToString());
        }
    }
}

}

我正在以管理员身份运行 Visual Studio(2019 社区)和模拟器。这似乎是理所当然的事,但我无法弄清楚。

最佳答案

谢谢大家,现在明白了。我以为字符串需要是UTF-8,但事实证明它需要是base64编码的。

关于c# - Azure队列存储 Visual Studio 本地主机从QueueClient发送到毒队列的所有队列消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62400706/

相关文章:

c# - asp.net Textbox Textmode Number,只允许数字

c# - 使用 Web API 返回图像

azure - 如何在 Azure 中设计 SQL 数据库?

Azure 应用服务 - HTTP 错误 500.30 - ANCM 进程内启动失败

azure - 迁移 Azure VM 以使用 12 个月的免费服务

.net-core - 如何在我的.netcore代码中获取Azure函数应用程序操作ID

c# - 如何将附加参数传递给 Blob 触发函数

c# - WPF 图像到字节[]

c# - .NET 紧凑框架中清理资源的最佳方法

c# - 在 b2c 中的用户注册时触发 azure 函数