【问题标题】:Azure: How to create an Event subscription programmaticallyAzure:如何以编程方式创建事件订阅
【发布时间】:2021-04-12 20:16:43
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    请在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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-19
      • 1970-01-01
      • 2018-08-06
      • 2021-04-17
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      相关资源
      最近更新 更多