我们在升级一个POS系统的时候,决定使用微软公有云计算平台下的Azure ServiceBus 进行POS客户端与服务器的交互。

本文主要时作者在学习使用 Azure SDK for .NET 操作由世纪互联运营的 中国区Azure 上的 Service Bus。


 

目录
一、安装AzureServiceBus程序集

二、在Portal创建命名空间

三、通过代码创建Topic

四、通过代码创建订阅

五、创建并发送消息

六、消费消息


  

1.通过nuget安装程序集

using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;

Azure service bus Topic基本用法

using Microsoft.Azure;

Azure service bus Topic基本用法

2. 在Portal创建 service bus 命名空间:

Azure service bus Topic基本用法

 

只有标准级别可以使用主题(Topic),因此创建命名空间时,请选择标准;

也可以创建后,在缩放选项卡里调整为标准。

 Azure service bus Topic基本用法

3.创建主题,可以通过portal创建,也可以通过代码创建:

Azure service bus Topic基本用法

 

 通过代码创建主题:

 1 // Create the topic if it does not exist already.
 2             string connectionString =
 3                 CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
 4 
 5             var namespaceManager =
 6                 NamespaceManager.CreateFromConnectionString(connectionString);
 7 
 8             if (!namespaceManager.TopicExists("TestTopic"))
 9             {
10 
11                 //默认的createtopic方法
12                  namespaceManager.CreateTopic("TestTopic");
13 
14 
15                 // 通过TopicDescription构建一个重载
16                 //TopicDescription td = new TopicDescription("TestTopicCustomer");
17                 //td.MaxSizeInMegabytes = 5120;
18                 //td.DefaultMessageTimeToLive = new TimeSpan(0, 1, 0);
19                 //if (!namespaceManager.TopicExists("TestTopicCustomer"))
20                 //{
21                 //    namespaceManager.CreateTopic(td);
22                 //}
23 
24             }
View Code

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2022-02-23
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
猜你喜欢
  • 2021-12-01
  • 2021-06-27
  • 2021-07-13
  • 2022-02-23
  • 2022-12-23
  • 2021-10-06
  • 2022-01-08
相关资源
相似解决方案