Search code examples
azureazureservicebusazureportalazure-blob-trigger

Creating topic filter rule for event type Microsoft.Storage.BlobCreated in Azure Portal


In Azure Portal, I have created a Blob Storage event that is triggered when a .zip file is created. The endpoint of that event is a Service Bus Topic. In this topic I have a subscription with a default rule (Filter 1=1).

I want to create rule, that will pass only the messages from this event. Normally I would do a Correlation Filter with Label property, but unfortunatelly in the message from the blob storage this Label property is empty.

I have tried:

Key Value
eventType Microsoft.Storage.BlobCreated

but it didn't work.

The message that I get:

System and Custom Properties

Message Text:

{
  "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"
}

Am I doing something wrong? Is there possibility to set the Label property of the blob message?


Solution

  • As @GauravMantri said, we cannot define filtering rules based on the content of the message in Azure service bus topic. The filtering rule just can be based on user-defined properties and system properties.

    enter image description here

    So if you implement the function, we just can do that on Event Grid level. We can create a filtering rule with event types and subjects.

    For example

    "filter": {
                "subjectBeginsWith": "<>",
                "subjectEndsWith": ".zip",
                "includedEventTypes": [
                    "Microsoft.Storage.BlobCreated"
                ],
                "advancedFilters": [],
                "enableAdvancedFilteringOnArrays": true
            },
    

    For more details, please refer to

    https://learn.microsoft.com/en-us/azure/service-bus-messaging/topic-filters

    https://learn.microsoft.com/en-us/azure/event-grid/event-filtering

    https://learn.microsoft.com/en-us/azure/event-grid/handler-service-bus