Satyajit
Satyajit

Reputation: 2071

azure event grid - create subscription with azure storage queue as endpointType

We can subscribe to an event grid topic via a storage queue using Azure CLI as mentioned:

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

When using the 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 = ""
        }

   };

I am not getting any properties or methods to set the endpoint-type and endpoint as mentioned in the CLI command.

Can anyone help me how I can set the endpoint-type as storagequeue using the c# nuget library

Upvotes: 1

Views: 869

Answers (2)

J. Kalyana Sundaram
J. Kalyana Sundaram

Reputation: 301

Here's the C# sample for using a storage queue as a destination in Microsoft.Azure.Management.EventGrid 2.0.0-preview:

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

Upvotes: 1

Roman Kiss
Roman Kiss

Reputation: 8235

you should use the following class:

    [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; }
    }

from Microsoft.Azure.Management.EventGrid 2.0.0-preview

Also, in this preview can be populated a DeadLetterDestination and RetryPolicy properties.

For DeadLetterDestination use the following class:

    [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; }
    }

Upvotes: 1

Related Questions