Azure服务总线-消息直接进入死信队列

标签 azure azure-functions azureservicebus azure-servicebus-queues

我有以下代码将消息发送到总线:

var queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

var message = new Message(poco.SerializeToBytes());

await queueClient.SendAsync(message);

但他们似乎直接进入死信消息计数:

enter image description here

我还创建了一个 Azure 函数来接收消息:

    [FunctionName("ServiceBusFunction")]
    public static void Run([ServiceBusTrigger("schedule", AccessRights.Listen, Connection = "ServiceBusConnection")]byte[] myQueueItem, TraceWriter log)
    {
        log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
    }

当我关闭该功能时,在创建该功能之前,消息已进入事件消息计数。我尝试在本地运行该函数,但该函数没有被命中。我觉得我在从函数中获取总线上的消息方面缺少一些基本的东西?

最佳答案

如果您查看 Function App 日志,您可能会看到类似的错误

Exception binding parameter 'myQueueItem'. Microsoft.Azure.WebJobs.ServiceBus: The BrokeredMessage with ContentType 'null' failed to deserialize to a byte[] with the message: 'There was an error deserializing the object of type System.Byte[]. The input source is not correctly formatted.'. System.Runtime.Serialization: There was an error deserializing the object of type System.Byte[]. The input source is not correctly formatted. System.Runtime.Serialization: The input source is not correctly formatted. 2018-03-01T15:14:41.578

Function App 尝试处理您的消息 10 次(默认),然后使用

将其放入 DLQ

Message could not be consumed after 10 delivery attempts.

问题与以下事实有关:您从"new".NET 标准服务总线客户端发送消息,而 Function App v1 使用“旧”基于 BrokeredMessage 的客户端。并且它们在二进制级别上不兼容,请参阅 this issue .

在包含服务总线绑定(bind)的 Function App v2 准备就绪之前,您应该更好地使用旧的服务总线客户端来发送消息。如果您必须使用新客户端,请参阅上面链接的问题中的一些解决方法,例如this comment .

关于Azure服务总线-消息直接进入死信队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49051829/

相关文章:

c++ - 在 Linux 上使用 Qt 连接到 Azure SQL Server

azure - 如何获取 Azure SQL 性能计数器

python - 如何将所有请求路由到单个 azure 函数并维护路由

azure - Azure 中的关联组

mysql - 无法查看 Azure 为 Azure Database for MySQL 创建的第一个备份

python - 函数/主机 key 是否可以在用 Python 编写的 Azure 函数中直接使用?

python - 语言 worker 如何使用Python在Azure函数中工作?

Azure ServiceBus 单元测试

azure - 如何动态更新很长的处理消息的锁定 - Azure.Messaging.ServiceBus;

使用应用服务的 Azure MSI