【问题标题】:azure event grid - create subscription with azure storage queue as endpointTypeazure 事件网格 - 使用 azure 存储队列作为 endpointType 创建订阅
【发布时间】:2018-07-03 02:11:57
【问题描述】:

如前所述,我们可以使用 Azure CLI 通过存储队列订阅事件网格主题:

az eventgrid event-subscription create \
  --topic-name demotopic \
  -g myResourceGroup \
  --name eventsub1 \
  --endpoint-type storagequeue \
  --endpoint <storage-queue-url>

使用 Microsoft.Azure.Management.EventGrid 时:

EventSubscription eventSubscription = new EventSubscription()
    {
        Destination = new WebHookEventSubscriptionDestination()
        {
             EndpointUrl = endpointUrl
        },
        // The below are all optional settings
        EventDeliverySchema = EventDeliverySchema.EventGridSchema,
        Filter = new EventSubscriptionFilter()
        {
             // By default, "All" event types are included
             IsSubjectCaseSensitive = false,
             SubjectBeginsWith = "",
             SubjectEndsWith = ""
        }

   };

我没有得到任何属性或方法来设置 CLI 命令中提到的端点类型和端点。

谁能帮助我如何使用 c# nuget 库将端点类型设置为存储队列

【问题讨论】:

    标签: azure azure-eventgrid


    【解决方案1】:

    您应该使用以下类:

        [JsonObject("StorageQueue"), JsonTransformation]
        public class StorageQueueEventSubscriptionDestination : EventSubscriptionDestination
        {
            // Methods
            public StorageQueueEventSubscriptionDestination();
            public StorageQueueEventSubscriptionDestination(string resourceId = new string(), string queueName = new string());
    
            // Properties
            [JsonProperty(PropertyName="properties.queueName")]
            public string QueueName { get; set; }
            [JsonProperty(PropertyName="properties.resourceId")]
            public string ResourceId { get; set; }
        }
    

    来自 Microsoft.Azure.Management.EventGrid 2.0.0-preview

    此外,在此预览中可以填充 DeadLetterDestinationRetryPolicy 属性。

    对于 DeadLetterDestination,使用以下类:

        [JsonObject("StorageBlob"), JsonTransformation]
        public class StorageBlobDeadLetterDestination : DeadLetterDestination
        {
            // Methods
            public StorageBlobDeadLetterDestination();
            public StorageBlobDeadLetterDestination(string resourceId = new string(), string blobContainerName = new string());
    
            // Properties
            [JsonProperty(PropertyName="properties.blobContainerName")]
            public string BlobContainerName { get; set; }
            [JsonProperty(PropertyName="properties.resourceId")]
            public string ResourceId { get; set; }
        }
    

    【讨论】:

    【解决方案2】:

    这是在 Microsoft.Azure.Management.EventGrid 2.0.0-preview 中使用存储队列作为目标的 C# 示例:

    来自https://github.com/Azure-Samples/event-grid-dotnet-publish-consume-events/blob/master/EGManageArmEventSubscriptions/EGManageArmEventSubscriptions/Program.cs

        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 = ""
            }
        };
    

    【讨论】:

      猜你喜欢
      • 2020-02-22
      • 2020-04-29
      • 2019-01-07
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 2020-03-31
      • 2022-11-07
      相关资源
      最近更新 更多