question

Ketan-7786 avatar image
0 Votes"
Ketan-7786 asked Ketan-7786 commented

How to filter data from xml in service bus topics subscription

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered Ketan-7786 commented

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.


image.png (75.2 KiB)
image.png (10.2 KiB)
· 12
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HI Mayank ,

thank you so much for your response on my question
I am new in Azure

could you please more elaborate on this like how can configure subscriptions to find messages that have desired properties
like MoveToLocation Id = 5 or 10 then only send data to queue
expecting some steps with syntax

0 Votes 0 ·

HI Mayank ,

thank you so much for your response on my question
I am new in Azure

could you please more elaborate on this like how can configure subscriptions to find messages that have desired properties
like MoveToLocation Id = 5 or 10 then only send data to queue
expecting some steps with syntax

0 Votes 0 ·

@YogeshVEDPATHAK-7786 I have updated my answer. The SQL filter will be as below once you have deleted the default filter 1=1
MoveToLocationID = 5 OR MoveToLocationID = 10

0 Votes 0 ·

69420-image.png

Please have look into attached image this will work ?


0 Votes 0 ·
image.png (33.7 KiB)
Show more comments

Hi Mayank ,
what if when they only want to send data to MoveToLocationId 10
it should be like MoveToLocationID = 10 It will work right ?

0 Votes 0 ·
Show more comments