[英]how to receive N number of messages at time from azure service bus topic subscription
[英]How to selectively receive Azure Service Bus messages by time interval?
我一直在開發一個 Azure 服務總線庫,它抽象和簡化了Microsoft.Azure.ServiceBus
.NET API 的重要部分。
以下代碼提供了使用該庫的訂閱操作示例:
/// <summary>
/// Subscribes string types events.
/// </summary>
/// <param name="eventBus">The event bus.</param>
private static void SubscribeStringEvents(IEventBus eventBus)
{
IEventBusEventHandler<string> stringEventHandler = new StringEventHandler();
eventBus.Subscribe("topicId", stringEventHandler);
}
目前,當客戶端訂閱指定主題的string
類型時,底層的ISubscriptionClient
將自動連接到相應的主題string
訂閱。 一旦建立連接,所有存儲在string
subscription 中的消息都會被注冊的stringEventHandler
接收。 stringEventHandler
也將接收進一步發布的string
消息。 考慮的唯一時間限制是消息不應過期(因此,應移至死信隊列)。
但是,在訂閱string
類型時,我還希望支持僅接收在stringEventHandler
注冊后發布的消息的可能性 - 過去的消息應保留存儲在相應的string
訂閱中。
支持這兩種行為的最佳方法是什么? 不幸的是, Microsoft.Azure.ServiceBus
.NET API 的文檔很少。
查找來自 Microsoft 的示例: TopicFilters
它使用舊的WindowsAzure.ServiceBus (4.1.3)
庫。 它的使用方式與當前版本略有不同。 不過你可以拿is作為參考。
SqlFilter sqlfilter = new SqlFilter("sys.EnqueuedTimeUtc >= @datetime");
sqlfilter.Parameters.Add("@datetime", DateTime.Parse("2019-12-04 16:56"));
Filter filter = sqlfilter.Preprocess();
var messages = subscriptionClient.PeekBatch(100);
Console.WriteLine("filtered messages: ");
var filteredMessages = from x in messages where filter.Match(x) select x;
var filteredMessagesList = filteredMessages.ToList();
補充教程:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.