Search code examples
.netazureservicebusazure-rm-templateazure-servicebus-topicsazure-servicebus-subscriptions

Service Bus messages filtering by label


Is it possible to add messages filtering rule (by label) on service bus level not for specified subscription or topic? I need to make such filtering in ARM template. Is answer is yes how such template should looks like?


Solution

  • Microsoft Azure Service Bus is a fully managed enterprise message broker with message queues and publish-subscribe topics.

    Message sent to a Service Bus Topic can be received from it's subscription created under the Topic. Subscribers can define which message they want to received from a Topic. The messages are specified in the form of one or more name subscription rules. Each rule consist of conditions to select and filter messages.

    If rules are not configured for each subscription then it will accept all the incoming message and we won't be able to apply filter. So you will need the subscription and topic for applying filters.

    We use Correlation Filters, one of the three topic subscription filters of service bus for Service Bus messages filtering by label. The following ARM template format shows how we can use it.

    {
      "name": "string",
      "type": "Microsoft.ServiceBus/namespaces/topics/subscriptions/rules",
      "apiVersion": "2017-04-01",
      "properties": {
        "action": {
            ...
        },
        "filterType": "string",
        "correlationFilter": {
          "properties": {},
          "correlationId": "string",
          "messageId": "string",
          "to": "string",
          "replyTo": "string",
          "label": "string",
          ...
        }
      }
    }
    

    For more information check this Auto Filter Messages into Subscriptions in Azure Service Bus Topic and Microsoft.ServiceBus document.