所以我最近得到了使用的需要Service Bus Topic and Subscriptions,我已經關注了很多文章和教程。我已經能夠成功地實現 Microsoft 的服務總線入門主題,并且還成功地使用Visual Studio 2017's Worker Role模板來訪問數據庫。但是,我對如何正確地“結合”兩者感到困惑。雖然服務總線入門主題文章展示了如何創建 2 個應用程序,一個用于發送,一個用于接收然后退出,但該Worker Role模板似乎無休止地循環使用await Task.Delay(10000);.我不確定如何正確地“網格化”兩者。從本質上講,我希望我Worker Role能一直活著并永遠聆聽訂閱的條目(或直到它明顯退出)。任何指導都會很棒!PS:如果您有興趣,我已經問過一個相關的問題,關于我應該在StackExchange - Software Engineering 的案例場景中使用的適當技術。using System;using System.Text;using System.Threading.Tasks;using Microsoft.Azure.ServiceBus;namespace TopicsSender { internal static class Program { private const string ServiceBusConnectionString = "<your_connection_string>"; private const string TopicName = "test-topic"; private static ITopicClient _topicClient; private static void Main(string[] args) { MainAsync().GetAwaiter().GetResult(); } private static async Task MainAsync() { const int numberOfMessages = 10; _topicClient = new TopicClient(ServiceBusConnectionString, TopicName); Console.WriteLine("======================================================"); Console.WriteLine("Press ENTER key to exit after sending all the messages."); Console.WriteLine("======================================================"); // Send messages. await SendMessagesAsync(numberOfMessages); Console.ReadKey(); await _topicClient.CloseAsync(); }
2 回答

慕的地8271018
TA貢獻1796條經驗 獲得超4個贊
考慮到更新問題 Update #1 (2018/08/09) 的復雜性,我提供了一個單獨的答案。
發送方和接收方使用不同的庫。
發件人 - Microsoft.Azure.ServiceBus
接收器 - WindowsAzure.ServiceBus
Microsoft.Azure.ServiceBus 將消息對象作為 Message,其中 WindowsAzure.ServiceBus 具有 BrokeredMessage。
Microsoft.Azure.ServiceBus 中有一個RegisterMessageHandler方法可用,這是 WindowsAzure.ServiceBus 中 client.OnMessage() 的替代方法。通過使用它,偵聽器將消息作為 Message 對象接收。這個庫支持異步編程,正如你所期望的。
請參閱此處獲取來自兩個庫的示例。
- 2 回答
- 0 關注
- 237 瀏覽
添加回答
舉報
0/150
提交
取消