Azure资源管理库用于C# – 创建事件中心

huangapple go评论73阅读模式
英文:

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;

huangapple
  • 本文由 发表于 2023年6月29日 20:19:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76581000.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定