【发布时间】:2015-10-19 08:03:16
【问题描述】:
我有一个控制台应用程序来读取 Azure 服务总线上订阅中存在的所有代理消息。我那里有大约 3500 条消息。这是我阅读消息的代码:
SubscriptionClient client = messagingFactory.CreateSubscriptionClient(topic, subscription);
long count = namespaceManager.GetSubscription(topic, subscription).MessageCountDetails.ActiveMessageCount;
Console.WriteLine("Total messages to process : {0}", count.ToString()); //Here the number is showing correctly
IEnumerable<BrokeredMessage> dlIE = null;
dlIE = client.ReceiveBatch(Convert.ToInt32(count));
当我执行代码时,在 dlIE 中,我只能看到 256 条消息。我也尝试过像 client.PrefetchCount 这样给出预取计数,但它也只返回 256 条消息。
我认为一次可以检索的消息数量有一些限制。但是在RecieveBatch方法的msdn页面上没有提到这样的事情。如何一次检索所有消息?
注意:
我只想读取消息,然后让它存在于服务总线上。因此我不使用
message.complete方法。我无法从服务总线中删除并重新创建主题/订阅。
编辑:
我像这样使用 PeekBatch 而不是 ReceiveBatch:
IEnumerable<BrokeredMessage> dlIE = null;
List<BrokeredMessage> bmList = new List<BrokeredMessage>();
long i = 0;
dlIE = subsciptionClient.PeekBatch(Convert.ToInt32(count)); // count is the total number of messages in the subscription.
bmList.AddRange(dlIE);
i = dlIE.Count();
if(i < count)
{
while(i < count)
{
IEnumerable<BrokeredMessage> dlTemp = null;
dlTemp = subsciptionClient.PeekBatch(i, Convert.ToInt32(count));
bmList.AddRange(dlTemp);
i = i + dlTemp.Count();
}
}
我的订阅中有 3255 条消息。当第一次调用 peekBatch 时,它会收到 250 条消息。所以它使用PeekBatch(250,3225) 进入while 循环。每次只收到 250 条消息。我在输出列表中的最终总消息是 3500 重复。我无法理解这是如何发生的。
【问题讨论】:
标签: c# azure azureservicebus azure-servicebus-queues azure-servicebus-topics