azure - ServiceBus 重试策略不适用于 QueueClient

标签 azure azure-functions servicebus

我想限制 Azure ServiceBus 队列接收器中的重试次数。

使用带有 MaxRetryCount:3 的控制台应用程序发送消息

private static async Task MainAsync()
    {
        string connectionString = ConfigurationManager.AppSettings["ServiceBusConnection"];
        QueueClient queueClient = QueueClient.CreateFromConnectionString(connectionString, QueueName);
        queueClient.RetryPolicy = new RetryExponential(
                minBackoff: TimeSpan.FromSeconds(0),
                maxBackoff: TimeSpan.FromSeconds(30),
                maxRetryCount: 3);

        string tradeData = File.ReadAllText("TradeSchemaDemo.json");
        var message = new BrokeredMessage(tradeData);
        await queueClient.SendAsync(message);
        await queueClient.CloseAsync();
    }

另一边我有Azure功能来接收消息,

public static void run([ServiceBusTrigger("TestQueue", AccessRights.Manage, Connection = "servicebusconnection")]string myqueueitem, TraceWriter log)
    {
        retry++;
        System.Console.WriteLine($"Retry attempt {retry}");
        throw new System.Exception("Human error");
        log.Info($"c# servicebus queue trigger function processed message: {myqueueitem}");
    }

不过,我的函数调用了 10 次。为什么??

最佳答案

在这种情况下,RetryPolicy 定义发送操作的重试次数,而不是接收端。

接收方重试次数由队列属性最大传递计数定义。您可以使用 Service Bus Explorer 等工具在队列级别进行设置,或者在创建队列时以编程方式进行设置:

var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
var queue = new QueueDescription(queueName);
queue.MaxDeliveryCount = 3;
if (!namespaceManager.QueueExists(queueName))
    namespaceManager.CreateQueue(queue);

关于azure - ServiceBus 重试策略不适用于 QueueClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50754805/

相关文章:

azure - 使用 AZ cli 命令在 Azure 中创建 Web 应用程序

Azure 函数 (Python) 和 Blob 存储绑定(bind)错误

azure - 将长时间运行的作业解耦为 azure 函数..如何获取整体状态?

asp.net-mvc - 将服务总线用于 Asp.net Web API

azure - 什么是 Azure Appfabric 服务总线连接包...?

node.js - Azure:按照文档完成后,使用 Azure REST API 删除表不起作用

c# - 使用 UseWindowsAzureActiveDirectoryBearerAuthentication 从 Azure 使用 Id_token

Azure 调度程序 : first working day of every month

redis - .net core 2.1 redis 缓存在 azure functions v2 中

azure - 从 Azure 函数服务总线触发器的配置中读取 TopicName 不起作用