问题描述
在 Azure 门户中,我创建了一个 Blob 存储事件,该事件在创建 .zip 文件时触发。该事件的端点是服务总线主题。在本主题中,我有一个带有默认规则的订阅(过滤器 1=1)。
我想创建规则,该规则将仅传递来自此事件的消息。 通常我会使用 Label 属性做一个相关过滤器,但不幸的是,在来自 blob 存储的消息中,此 Label 属性为空。
我试过了:
-
sql 过滤器:
Subject like "%containers/my-test-container/%"
键 | 价值 |
---|---|
事件类型 | Microsoft.Storage.BlobCreated |
但是没有用。
我收到的消息:
消息文本:
{
"topic": ***,"subject": "/blobServices/default/containers/my-test-subscription/blobs/test.zip","eventType": "Microsoft.Storage.BlobCreated","id": ***,"data": {
"api": "PutBlob","clientRequestId": ***,"requestId": ***,"eTag": "0x8D8EDDB53852C51","contentType": "application/x-zip-compressed","contentLength": 1118884,"blobType": "BlockBlob","url": "***.blob.core.windows.net/my-test-subscription/test.zip","sequencer": "000000000000000000000000000008CE0000000006ddc175","storageDiagnostics": {
"batchId": ***
}
},"dataVersion": "","MetadataVersion": "1","eventTime": "2021-03-23T09:09:12.7782481Z"
}
我做错了吗?是否可以设置 blob 消息的 Label 属性?
解决方法
正如@GauravMantri 所说,我们无法根据 Azure 服务总线主题中的消息内容定义过滤规则。过滤规则只能基于用户自定义属性和系统属性。
因此,如果您实现该功能,我们就可以在事件网格级别执行此操作。我们可以创建带有事件类型和主题的过滤规则。
例如
"filter": {
"subjectBeginsWith": "<>","subjectEndsWith": ".zip","includedEventTypes": [
"Microsoft.Storage.BlobCreated"
],"advancedFilters": [],"enableAdvancedFilteringOnArrays": true
},
详情请参考
https://docs.microsoft.com/en-us/azure/service-bus-messaging/topic-filters
https://docs.microsoft.com/en-us/azure/event-grid/event-filtering
https://docs.microsoft.com/en-us/azure/event-grid/handler-service-bus