本文整理汇总了C#中NamespaceManager.CreateEventHubIfNotExistsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceManager.CreateEventHubIfNotExistsAsync方法的具体用法?C# NamespaceManager.CreateEventHubIfNotExistsAsync怎么用?C# NamespaceManager.CreateEventHubIfNotExistsAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceManager
的用法示例。
在下文中一共展示了NamespaceManager.CreateEventHubIfNotExistsAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEventHubAsync
public async Task<EventHubDescription> CreateEventHubAsync()
{
string serviceBusNamespace = "iotmc-ns";
string serviceBusManageKey = "<< Add your SAS here >>";
string eventHubName = "IoTMC";
string eventHubSASKeyName = "Device01";
Uri serviceBusUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceBusNamespace, string.Empty);
TokenProvider tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", serviceBusManageKey);
NamespaceManager nameSpaceManager = new NamespaceManager(string.Format("//{0}/", serviceBusUri.Host), tokenProvider);
string eventHubKey = SharedAccessAuthorizationRule.GenerateRandomKey();
EventHubDescription eventHubDescription = new EventHubDescription(eventHubName)
{
PartitionCount = 8,
MessageRetentionInDays = 1
};
SharedAccessAuthorizationRule eventHubSendRule = new SharedAccessAuthorizationRule(eventHubSASKeyName, eventHubKey, new[] { AccessRights.Send, AccessRights.Listen });
eventHubDescription.Authorization.Add(eventHubSendRule);
eventHubDescription = await nameSpaceManager.CreateEventHubIfNotExistsAsync(eventHubDescription);
string eventHubSASKey = ((SharedAccessAuthorizationRule)eventHubDescription.Authorization.First()).PrimaryKey;
return eventHubDescription;
}
示例2: CreateEventHubIfNotExists
public static void CreateEventHubIfNotExists(string eventHubName, int numberOfPartitions, NamespaceManager manager)
{
try
{
// Create the Event Hub
Trace.WriteLine("Creating Event Hub...");
EventHubDescription ehd = new EventHubDescription(eventHubName);
ehd.PartitionCount = numberOfPartitions;
manager.CreateEventHubIfNotExistsAsync(ehd).Wait();
}
catch (AggregateException agexp)
{
Trace.WriteLine(agexp.Flatten());
}
}