Search code examples
azureazureservicebuspublish-subscribeazure-servicebus-topicsazure-servicebus-subscriptions

How to filter the Azure Servicebus Topic Subscription based on the dictionary key


I have a Azure Servicebus topie and multiple subscriptions.message will be posted with dictionary type. based on the dictionary key will I be able to filter the message. All the examples are shown based on the hierarchy https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-sql-filter#property_name . here is the payload and I want to filter based on the dict key which is DataReady, Datapending, Dataprocessed.

Message 1:
    {
      "DataReady": "{\"RequestId\":\"605dc8dda700a7b9c25eb22a\"\"Status\":"Initiated\"}"
    }
    
Message 2:
    {
      "DataProcessed": "{\"RequestId\":\"605dc8dda700a7b9c25eb22a\"\"Status\":"Processed\"}"
    }
    
message 3:
    {
      "DataPending": "{\"RequestId\":\"605dc8dda700a7b9c25eb22a\"\"Status\":"pending\"}"
    }

Solution

  • Filtering message based on message content is not supported by Azure Service Bus. You can define filtering rules either on the system properties (like id, label etc.) or custom properties (user defined metadata in key/value pair form) of a message only.

    Please see this link for examples on setting filtering rules: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-filter-examples.

    One thing you could do is define the status ("Initiated", "Processed" or "Pending") as one of the custom properties (e.g. "MessageStatus") of a message and then you can define the filtering rule on that property.