【发布时间】:2019-06-02 23:11:19
【问题描述】:
我正在尝试使用 Microsoft.Azure.ServiceBus.dll(在 .Net Core 2.1 中)读取 Azure ServiceBus 订阅上的所有现有消息,但我遇到了困难。
我发现了很多例子,以下应该可以工作,但它没有:
var client = new SubscriptionClient(ServiceBusConnectionString, topicName, subscription, ReceiveMode.PeekLock, null);
var totalRetrieved = 0;
while (totalRetrieved < count)
{
var messageEnumerable = subscriptionClient.PeekBatch(count);
//// ... code removed from this example as not relevant
}
我的问题是 .PeekBatch 方法不可用,我很困惑如何解决这个问题。
我已经从 GitHub (https://github.com/paolosalvatori/ServiceBusExplorer) 下载了 ServiceBusExplorer 的源代码,上面的代码示例几乎就是这样做的。但不在 .Net Core / Microsoft.Azure.ServiceBus 命名空间中。
不过,为了清楚起见,我正在尝试读取队列中已经存在的消息 - 我已经研究过其他示例,这些示例创建了响应新消息的侦听器,但我需要在消息之后以这种断开连接的方式工作已经入队了。
【问题讨论】: