英文:
Azure resource management library for C# - create an Event Hub
问题
Is it possible to create a new event hub in an event hub namespace programatically? The EventHubsNamespaceResource Class from the Azure.ResourceManager.EventHubs library does not seem to support this. Is there some other way?
ResourceGroupResource _resourceGroup;
public EventHubResource GetOrCreateEventHub(string eventHubNamespaceName, string eventHubName)
{
var eventHubNamespace = _resourceGroup.GetEventHubsNamespace(eventHubNamespaceName).Value;
try
{
return eventHubNamespace.GetEventHub(eventHubName).Value;
}
catch (Exception ex)
{
// TODO: create a new event hub
}
}
英文:
Is it possible to create a new event hub in an event hub namespace programatically? The EventHubsNamespaceResource Class from the Azure.ResourceManager.EventHubs library does not seem to support this. Is there some other way?
ResourceGroupResource _resourceGroup;
public EventHubResource GetOrCreateEventHub(string eventHubNamespaceName, string eventHubName)
{
var eventHubNamespace = _resourceGroup.GetEventHubsNamespace(eventHubNamespaceName).Value;
try
{
return eventHubNamespace.GetEventHub(eventHubName).Value;
}
catch (Exception ex)
{
// TODO: create a new event hub
}
}
答案1
得分: 0
The EventHubCollection
类有一个 CreateOrUpdate
方法,可用于创建一个新的事件中心。
var eventHubNamespace = _resourceGroup.GetEventHubsNamespace(eventHubNamespaceName).Value;
var eventHubName = "some_name";
var coll = eventHubNamespace.GetEventHubs();
var data = new EventHubData()
{
CaptureDescription = new CaptureDescription()
{
Destination = new EventHubDestination()
{
ArchiveNameFormat = "some/path/{Year}{Month}{Day}/{Namespace}-{EventHub}-{PartitionId}-{Hour}{Minute}{Second}",
BlobContainer = "mycontainer",
Name = "EventHubArchive.AzureBlockBlob",
StorageAccountResourceId = new Azure.Core.ResourceIdentifier(storageAccountResourceId),
},
Enabled = true,
Encoding = EncodingCaptureDescription.Avro,
IntervalInSeconds = 900,
SizeLimitInBytes = 314572800,
},
MessageRetentionInDays = 2,
};
return coll.CreateOrUpdate(WaitUntil.Completed, eventHubName, data).Value;
英文:
The EventHubCollection
class has CreateOrUpdate
method that can be used to create a new event hub.
var eventHubNamespace = _resourceGroup.GetEventHubsNamespace(eventHubNamespaceName).Value;
var eventHubName = "some_name";
var coll = eventHubNamespace.GetEventHubs();
var data = new EventHubData()
{
CaptureDescription = new CaptureDescription()
{
Destination = new EventHubDestination()
{
ArchiveNameFormat = "some/path/{Year}{Month}{Day}/{Namespace}-{EventHub}-{PartitionId}-{Hour}{Minute}{Second}",
BlobContainer = "mycontainer",
Name = "EventHubArchive.AzureBlockBlob",
StorageAccountResourceId = new Azure.Core.ResourceIdentifier(storageAccountResourceId),
},
Enabled = true,
Encoding = EncodingCaptureDescription.Avro,
IntervalInSeconds = 900,
SizeLimitInBytes = 314572800,
},
MessageRetentionInDays = 2,
};
return coll.CreateOrUpdate(WaitUntil.Completed, eventHubName, data).Value;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论