仅 ServiceBusReceiver PeekMessageAsync returns 最多 250 条 dlq 消息?

ServiceBusReceiver PeekMessageAsync only returns maximum of 250 dlq-messages?

我正在使用 ServiceBusReceiver(我想继续使用)从服务总线上的死信队列读取数据。

但是,receiver.PeekMessagesAsync(550) 最多只能从死信队列中提取 250 条消息??? 我怎样才能改变这个?我已经将它设置为获取 550 条消息,所以不知道该怎么做。

        string topic = "myTopic";
        string subscriptionAndDeadletterPath = @"mySubscription/$deadletterqueue";
        var paginationSize = 1000;
        var dlqCount = 0;
        var numberOfMessagesToFetchFromDlq = 550;

        try
        {
            await using var client = new ServiceBusClient(connectionString);
            var receiver = client.CreateReceiver(topic, subscriptionAndDeadletterPath, new ServiceBusReceiverOptions() { ReceiveMode = ServiceBusReceiveMode.PeekLock, PrefetchCount = paginationSize });
           
            var messagesFromDlq = await receiver.PeekMessagesAsync(numberOfMessagesToFetchFromDlq);
            dlqCount = messagesFromDlq.Count();
       

dlqCount 出于某种原因不会超过 250? int maxMessages 参数似乎在这个数字以上不起作用?

您传递给 PeekMessagesAsync 的消息数是将返回的最大消息数。无法保证批处理的最小大小;包含的消息数量取决于几个因素,其中影响最大的是网络将消息流式传输到客户端的速度。

我对 的回答更详细地讨论了上下文并提供了一些可能也适用于您的场景的想法。

请务必注意,与收到的消息相比,查看的消息存在一些行为差异。影响最大的是查看的消息未锁定且无法结算,因此此处不适用有关锁定令牌过期的注意事项。

我现在是这样解决的:

        string topic = "myTopic";
        string subscriptionAndDeadletterPath = @"mySubscription/$deadletterqueue";
        var sequence = 0;
        var continueWithNextIteration = true;
        var paginationSize = 100;
        var numberOfMessagesToFetchFromDlq = 250

            await using var client = new ServiceBusClient(connectionString);
            var receiver = client.CreateReceiver(topic, subscriptionAndDeadletterPath, new ServiceBusReceiverOptions() { ReceiveMode = ServiceBusReceiveMode.PeekLock, PrefetchCount = paginationSize });

            do
            {
                var messagesFromDlq = await receiver.PeekMessagesAsync(numberOfMessagesToFetchFromDlq, sequence);
                if (messagesFromDlq.Count() > 249)
                {
                    var nextSequenceSetting = await receiver.PeekMessagesAsync(2, Convert.ToInt32(messagesFromDlq.Last().SequenceNumber));
                    sequence = Convert.ToInt32(nextSequenceSetting.Last().SequenceNumber);
                    continueWithNextIteration = nextSequenceSetting.Count() > 1 ? true : false;
                }
             
            } while (continueWithNextIteration);