How to filter data from xml in service bus topics subscription

Ketan Patil 21 Reputation points
2021-02-17T19:18:36.177+00:00

Currently Its sending all orders data into queue I want to create rules in service bus topics subscription
when MoveToLocation Id = 5 or 10 then only send data to queue

xml
below are sample xml

<?xml version="1.0" encoding="utf-8"?>
<Orders xmlns="#">
<Order>
<OrderHeader>
<OrderId>123</OrderId>
<OrderType>EXTERNAL</OrderType>
<Note>
<DataTypes>Order</DataTypes>
<NoteUsed>External</NoteUsed>
<Value>ABC</Value>
</Note>
<OrderDateTime>2021-000:00:00Z</OrderDateTime>
<Status>Avaiable</Status>
<Action>Taken</Action>
<Currency>Rs</Currency>
<TotalAmount>2**</TotalAmount>
<SourceId>abc</SourceId>
<MoveToLocation>
<Id>3</Id>
<Type>house</Type>
</MoveToLocation>
</OrderHeader>
</Order>
</Orders>

Note (There is default rule exist for now in similar way I want to configure )

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
548 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 68,656 Reputation points
    2021-02-18T05:59:55.73+00:00

    Hi @YogeshVEDPATHAK-7786

    Welcome to Microsoft Q&A! Thanks for posting the question.

    The filter is never be used for filtering based on the content message. Rules/filters work on the specific property that you have defined on the message.

    In many scenarios, messages that have specific characteristics must be processed in different ways. To enable this processing, you can configure subscriptions to find messages that have desired properties and then perform certain modifications to those properties. While Service Bus subscriptions see all messages sent to the topic, you can only copy a subset of those messages to the virtual subscription queue. This filtering is accomplished using subscription filters. Such modifications are called filter actions. When a subscription is created, you can supply a filter expression that operates on the properties of the message. The properties can be both the system properties (for example, Label) and custom application properties (for example, StoreName.) The SQL filter expression is optional in this case. Without a SQL filter expression, any filter action defined on a subscription will be done on all the messages for that subscription.

    Before sending a message to the service bus you define message properties (any custom field with the value same as MoveToLocation ID in that message) which can be used for filtering the message at the subscription end.

    Updated:

    I have used service bus explorer to send the test messages with the custom property 'MoveToLocationID'

    While sending the message to the topic I have set the MoveToLocationID property as integer value to 3 in the message as it is in the message content. This needs to update/implemented at your sender application end that they should set the custom property with the message value so the filter should work correctly.
    69278-image.png

    At the subscription end, I have deleted the default rule 1=1 (SQL) and added new rule with the below filter:
    MoveToLocationID = 5 OR MoveToLocationID = 10

    69279-image.png

    Using the above rule only messages that have MoveToLocationID property with values as 5 and 10 will be accepted and other messages will be discarded at the subscription end where you have applied the above rule.

    Hope the above helps and please let me know if you have any queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


0 additional answers

Sort by: Most helpful