天蓝色事件网格-使用天蓝色存储队列作为EndpointType创建订阅

时间:2018-07-02 11:49:59

标签: azure azure-eventgrid

我们可以使用提到的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库将终结点类型设置为storagequeue

2 个答案:

答案 0 :(得分: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

此外,在此预览中还可以填充 DeadLetterDestination RetryPolicy 属性。

对于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; }
    }

答案 1 :(得分:1)

以下是在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 = ""
        }
    };