Reputation: 13
I want to send message to a particular subscription using brokered service(rest), the how can i do this.
If there are lots of subscriptions on a topic and i want to send message to the particular subscription.
Upvotes: 0
Views: 1853
Reputation: 13
Finally I got the answer for this question. Answer having the following steps.
@"<entry xmlns=""http://www.w3.org/2005/Atom"">
<title type=""text"">" + SubscriptionName + @"</title>
<content type=""application/xml"">
<SubscriptionDescription xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"" >
<DefaultRuleDescription>
<Filter i:type=""SqlFilter"">
<SqlExpression>" + "VenueId='" + venueId + "' or CustomerId='" + customerId + @"'</SqlExpression>
<CompatibilityLevel> 20 </CompatibilityLevel>
</Filter>
<Action i:type = ""EmptyRuleAction""/>
<Name>$Default</Name>
</DefaultRuleDescription>
</SubscriptionDescription>
</content>
</entry>";
webClient
with same name used in sql filters like belowwebClient.Headers.Add("CustomerId", customerId);
webClient.Headers.Add("VenueId", venueId);
Create the subscription. This subscription will be created and have some filters.
While retrieving message at client end also add these 2 headers in webClient
. So that it will receive messages only having filters for CustomerId
and VenueId
webClient.Headers.Add("CustomerId", customerId);
webClient.Headers.Add("VenueId", venueId);
webClient.Headers.Add("CustomerId", customerId);
webClient.Headers.Add("VenueId", venueId);
Upvotes: 0
Reputation: 3551
Each subscription on a topic should have its own rules (subscription), a client sending a message to a topic normally doesn't want to know to which subscription to send to.
If you do need this, try something like this:
Client -> Topic | Subscription 1 | *
| Subscription 2 | properties.customername = "A"
| Subscription 3 | properties.customername = "B"
| Subscription 4 | properties.special = "123"
To send a message to only one subscription, make sure all subscriptions have a unique subscription. In the above example, subscription 1 receives all messages, change this to something like this:
Client -> Topic | Subscription 1 | properties.customername EXISTS
| Subscription 2 | properties.customername = "A"
| Subscription 3 | properties.customername = "B"
| Subscription 4 | properties.special = "123"
more info: https://msdn.microsoft.com/library/azure/microsoft.servicebus.messaging.sqlfilter.sqlexpression.aspx
Another solutions could be to create a seperate topic to handle this, and this topic can "forward" all other request to your regular topic. (topics can be chained to create this behaviour) https://azure.microsoft.com/en-us/documentation/articles/service-bus-auto-forwarding/
Upvotes: 1