Azure服务总线-PeekBatchAsync返回的消息少于预期的消息 [英] Azure Service Bus - PeekBatchAsync returning less messages than expected

查看:81
本文介绍了Azure服务总线-PeekBatchAsync返回的消息少于预期的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Azure Service Bus主题中,我有一个包含1000多个消息的订阅.这些消息由工作角色使用. 出于监视目的,我希望先查看10条消息,以查看正在等待处理的消息类型.为了完成该任务,我创建了一个subscriptionclient,并调用了PeekBatchAsync方法.奇怪的行为是有时PeekBatchAsync返回少于10条消息(即2或4条消息).

In an Azure Service Bus Topic I have a subscription with more than 1000 messages. These messages are consumed by a worker role. For monitoring purposes, I want to peek first 10 messages, to see what kind of messages are waiting to be processed. To accomplish that task I create a subscriptionclient and I call method PeekBatchAsync . The strange behavior is that sometimes PeekBatchAsync returns less than 10 messages (i.e. 2 or 4 messages).

代码示例:

Dim subscriptionClient As SubscriptionClient = messagingFactory.CreateSubscriptionClient(topicName, subscriptionName)
Dim messages = Await subscriptionClient.PeekBatchAsync(10)

更多信息以澄清上下文:

More information to clarify the context:

  • 我确定订阅包含超过1000条消息
  • 该主题是使用EnablePartitioning = True
  • 创建的
  • 我正在使用Microsoft.ServiceBus v.2.3.4.0库
  • 我正在使用会话
  • 在大多数情况下,我收到的邮件数量正确(10),有时我收到的邮件较少.我不知道要复制该问题的确切条件是什么

我的问题是:为什么有时该方法返回的消息少于预期的?

My question is : Why sometimes the method returns less messages than expected?

推荐答案

我猜想Azure-ServiceBus的文档 ReceiveBatch-方法PeekBatchAsync的情况下也适用.基本上说:可能会返回邮件数量(在您的情况下为10),但不能保证.

I guess the documentation for the Azure-ServiceBus ReceiveBatch-method also applies in the case of PeekBatchAsync. Basically it says: The max. number of messages (in your case 10) might be returned but it's not guaranteed.

使用两个参数(int messageCount, TimeSpan serverWaitTime)应用重载时,我会遇到更好的结果.

I experienced better results when applying the overload taking two parameters: (int messageCount, TimeSpan serverWaitTime), where one can define a wait-time.

这篇关于Azure服务总线-PeekBatchAsync返回的消息少于预期的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆