其他分享
首页 > 其他分享> > Azure Service Bus(2)

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的控制台上生成的那个链接字符串;

 

标签:JProperty,Service,Bus,connectionString,var,Azure,new,message,entityPath
来源: https://www.cnblogs.com/ZkbFighting/p/14598869.html