Reputation: 4585
The older WindowsAzure.ServiceBus
library has a call CreateConsumerGroupIfNotExists
to create a consumer group on an azure eventhub. However, this is Net Framework 4.6 only. I'm trying to figure out how to create a consumer in netstandard2.0
from C# but I don't see an equivalent. Is there a way to do this?
Upvotes: 1
Views: 1932
Reputation: 4585
Peter Pan is correct in pointing out the C# API call for this. Here are some more details:
The variables in the code below come from the service client, the event hub and the subscription:
private static async Task EnsureConsumerGroup(string consumerGroupName)
{
var context = new AuthenticationContext($"https://login.windows.net/{MY_TENANT_ID}");
var token = await context.AcquireTokenAsync(
"https://management.core.windows.net/",
new ClientCredential(MY_CLIENT_ID, MY_CLIENT_SECRET)
);
var serviceClientCredentials = new TokenCredentials(token.AccessToken);
var eventHubManagementClient = new EventHubManagementClient(serviceClientCredentials)
{
SubscriptionId = MY_SUBSCRIPTION_ID
};
var consumerGroupResponse = await
eventHubManagementClient.ConsumerGroups.CreateOrUpdateWithHttpMessagesAsync(
MY_RESOURCE_GROUP_NAME,
MY_NAMESPACE_NAME,
MY_EVENT_HUB_NAME,
consumerGroupName,
new ConsumerGroup() // I don't know what this parameter is supposed to do.
);
}
Presumably you would handle the error condition in consumerGroupResponse.Response
as well.
See also:
Upvotes: 0
Reputation: 24148
Generally, you can directly use the REST API Create consumer group
to create EventHubs Consumer Group in any programming language.
In your scenario using C#, there is an API of Azure SDK for .NET ConsumerGroupsOperationsExtensions.CreateOrUpdate(IConsumerGroupsOperations, String, String, String, String, ConsumerGroup) Method
that you can use. And according to the information from NuGet Package Manager in Visual Studio 2017, as the figure below, the related package Microsoft.Azure.Management.EventHub
supports Netstandard.Library (>=1.6.1)
, so it should also support your current environment netstandard2.0
.
Upvotes: 1