Azure:如何以编程方式创建事件订阅

标签 azure azure-functions azure-storage azure-eventgrid

我有许多以编程方式创建的存储帐户,我想在每个帐户中创建一个事件订阅,以使用现有的 Azure Function 终结点监听 BlobCreated 事件。目前,我通过访问门户手动执行此操作,但至少可以说这是非常耗时的。

是否有任何可使用 Azure 凭据创建事件订阅的 C# 代码示例?

最佳答案

请在 GitHub 中查找示例

    static async Task CreateEventGridEventSubscriptionAsync(string azureSubscriptionId, string eventSubscriptionName, EventGridManagementClient eventGridMgmtClient)
    {
        Console.WriteLine($"Creating an event subscription to Azure subscription {azureSubscriptionId} with destination as queue {QueueName} under storage account {StorageAccountId}");

        string scope = $"/subscriptions/{azureSubscriptionId}";

        EventSubscription eventSubscription = new EventSubscription()
        {
            Destination = new StorageQueueEventSubscriptionDestination()
            {
                ResourceId = StorageAccountId,
                QueueName = QueueName
            },
            // The below are all optional settings
            EventDeliverySchema = EventDeliverySchema.EventGridSchema,
            Filter = new EventSubscriptionFilter()
            {
                IsSubjectCaseSensitive = false,
                SubjectBeginsWith = "",
                SubjectEndsWith = ""
            }
        };

        EventSubscription createdEventSubscription = await eventGridMgmtClient.EventSubscriptions.CreateOrUpdateAsync(scope, eventSubscriptionName, eventSubscription);
        Console.WriteLine("EventGrid event subscription created with name " + createdEventSubscription.Name);
    }

官方文档请在 MS Docs - IEventSubscriptionsOperations Interface 中查找

MS Docs - EventSubscriptionsOperationsExtensions.CreateOrUpdateAsync(IEventSubscriptionsOperations, String, String, EventSubscription, CancellationToken) Method

关于Azure:如何以编程方式创建事件订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65606705/

相关文章:

c# - 以编程方式获取 Azure 存储帐户属性

.net - Azure 应用服务日志警告区域的最大大小

c# - Azure KeyVault : how to create clientId and clientSecret?

c# - 如何将队列触发的 Azure Function 绑定(bind)到自定义对象

java - 如何连接local.settings.json的JDBC连接字符串?

c# - 类型 'System.Web.HttpInputStream' 未标记为可序列化

Azure Blob 存储与文件服务

azure - 我是否使用 Azure 表存储或 SQL Azure 作为我们的 CQRS 读取系统?

c# - Azure Blob 存储下载 : Server failed to authenticate,,但重试后正常

azure - 用于生成 Azure 函数成功和失败计数线图的 Kusto 查询