public static async Task<EventHubDescription> UpdateEventHub(string eventHubName, NamespaceManager namespaceManager) { // Add a consumer group EventHubDescription ehd = await namespaceManager.GetEventHubAsync(eventHubName); await namespaceManager.CreateConsumerGroupIfNotExistsAsync(ehd.Path, "consumerGroupName"); // Create a customer SAS rule with Manage permissions ehd.UserMetadata = "Some updated info"; string ruleName = "myeventhubmanagerule"; string ruleKey = SharedAccessAuthorizationRule.GenerateRandomKey(); ehd.Authorization.Add(new SharedAccessAuthorizationRule(ruleName, ruleKey, new AccessRights[] { AccessRights.Manage, AccessRights.Listen, AccessRights.Send })); EventHubDescription ehdUpdated = await namespaceManager.UpdateEventHubAsync(ehd); return ehd; }
public static void CreateEventHubAndConsumerGroup() { try { NamespaceManager manager = NamespaceManager.CreateFromConnectionString(GetServiceBusConnectionString()); // Create the Event Hub Console.WriteLine("Creating Event Hub..."); EventHubDescription ehd = new EventHubDescription(eventHubName); //ehd.PartitionCount = numberOfPartitions; manager.CreateEventHubIfNotExistsAsync(ehd.Path).Wait(); manager.CreateConsumerGroupIfNotExistsAsync(ehd.Path, consumerGroupName).Wait(); } catch (AggregateException agexp) { Console.WriteLine(agexp.Flatten()); } }
public static async Task <EventHubDescription> UpdateEventHub(string eventHubName, NamespaceManager namespaceManager) { // Add a consumer group EventHubDescription ehd = await namespaceManager.GetEventHubAsync(eventHubName); await namespaceManager.CreateConsumerGroupIfNotExistsAsync(ehd.Path, "consumerGroupName"); // Create a customer SAS rule with Manage permissions ehd.UserMetadata = "Some updated info"; string ruleName = "myeventhubmanagerule"; string ruleKey = SharedAccessAuthorizationRule.GenerateRandomKey(); ehd.Authorization.Add(new SharedAccessAuthorizationRule(ruleName, ruleKey, new AccessRights[] { AccessRights.Manage, AccessRights.Listen, AccessRights.Send })); EventHubDescription ehdUpdated = await namespaceManager.UpdateEventHubAsync(ehd); return(ehd); }