Azure Service Bus(2)

先去NuGet里安装Service Bus 组件

 

 

 下面是应用,贼简单

 var MethodCont = new JObject {
                                                   new JProperty("vendorCode",EclpNum),//商家编码
                                                   new JProperty("waybillCode",TripNumber),//申通运单号
                                                   new JProperty("weight",TripWeight),//重量
                                                   new JProperty("volume",Volume),//体积                 
                                                     };
var Send = JsonConvert.SerializeObject(MethodCont);
byte[] bytes = Encoding.UTF8.GetBytes(Send);
MemoryStream ms = new MemoryStream();
ms.Write(bytes, 0, bytes.Length);
var message = new Message(ms.ToArray());
message.Label = "xxxx";

string connectionString = ConfigurationManager.AppSettings.Get("connectionString").ToString();
string entityPath = ConfigurationManager.AppSettings.Get("entityPath").ToString();
ITopicClient topicClient = new TopicClient(connectionString, entityPath);
await topicClient.SendAsync(message);
<add key="connectionString" value="Endpoint=sb://zkb.servicebus.chinacloudapi.cn/;SharedAccessKeyName=zkb.backend.m;SharedAccessKey=zkb;" />
<add key="entityPath" value="xxxx" />
上面这两个key是在Azure的控制台上生成的那个链接字符串;

 

posted @ 2021-03-30 21:06  ProZkb  阅读(108)  评论(0编辑  收藏  举报