Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically query Event Hub Consumer Group (and create if required)

Does anyone know how to query and create consumer groups in Azure Event Hubs using the .NET SDK. I've googled loads and can only find a way through the REST API (which I can do, but it would nicer if I can do it through the SDK). Thanks in advance

like image 884
Ross Ellerington Avatar asked Feb 01 '26 00:02

Ross Ellerington


2 Answers

Does anyone know how to query and create consumer groups in Azure Event Hubs using the .NET SDK.

You could try to install this NuGet package, and as Sreeram said, we could use the NamespaceManager class to create consumer group.

var manager = NamespaceManager.CreateFromConnectionString("{your connection string}");
manager.CreateConsumerGroupIfNotExists("{eventHubPath}", "{consumergroup Name}");

After you executed the code, you will find the consumer group is created.

enter image description here

To get the consumer group, you could try to call EventHubClient.GetConsumerGroup method.

var factory = MessagingFactory.CreateFromConnectionString("{your connection string}");
var client = factory.CreateEventHubClient("{eventHubPath}"); 
EventHubConsumerGroup group = client.GetConsumerGroup("{consumergroup Name}");
like image 56
Fei Han Avatar answered Feb 04 '26 01:02

Fei Han


NamespaceManager.CreateConsumerGroupIfNotExistsAsync(...)

ConsumerGroupDescription realtimeCG = nsMgr.CreateConsumerGroupIfNotExists("PartitionedStream_AKA_EventHub_Name");
like image 30
Sreeram Garlapati Avatar answered Feb 04 '26 00:02

Sreeram Garlapati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!