我们可以使用提到的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
答案 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#示例:
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 = ""
}
};