Created
February 21, 2013 12:35
-
-
Save clemensv/5004431 to your computer and use it in GitHub Desktop.
I should talk about this more. SQL filters and rules on Service Bus Topics subscriptions. SQL action syntax http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.messaging.sqlruleaction.sqlexpression.aspx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace SqlFiltersAndRules | |
{ | |
using System; | |
using Microsoft.ServiceBus; | |
using Microsoft.ServiceBus.Messaging; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var nsm = NamespaceManager.Create(); | |
string ruletestName = "ruletest"; | |
if (nsm.TopicExists(ruletestName)) | |
{ | |
nsm.DeleteTopic(ruletestName); | |
} | |
nsm.CreateTopic(ruletestName); | |
nsm.CreateSubscription(ruletestName, "sub1", new FalseFilter()); | |
var sc = SubscriptionClient.Create(ruletestName, "sub1"); | |
sc.AddRule(new RuleDescription | |
{ | |
Name = "rule1", | |
Filter = new SqlFilter("sys.SequenceNumber % 2 = 0"), | |
Action = new SqlRuleAction("SET ThisMessageIs='Even'; SET FullName = FirstName + ' ' + LastName;") | |
}); | |
sc.AddRule(new RuleDescription | |
{ | |
Name = "rule2", | |
Filter = new SqlFilter("sys.SequenceNumber % 2 <> 0"), | |
Action = new SqlRuleAction("SET ThisMessageIs='Odd'; SET FullName = LastName + ' ' + FirstName;") | |
}); | |
var tc = TopicClient.Create(ruletestName); | |
tc.Send( new BrokeredMessage { Properties = {{"FirstName", "Clemens"}, {"LastName", "Vasters"}}}); | |
tc.Send(new BrokeredMessage { Properties = { { "FirstName", "Abhishek" }, { "LastName", "Lal" } } }); | |
tc.Send(new BrokeredMessage { Properties = { { "FirstName", "Ziv" }, { "LastName", "Rafalovich" } } }); | |
tc.Send(new BrokeredMessage { Properties = { { "FirstName", "Ruppert" }, { "LastName", "Koch" } } }); | |
for (int i = 0; i < 4; i++) | |
{ | |
var msg = sc.Receive(); | |
Console.WriteLine("{0} {1}", msg.Properties["ThisMessageIs"], msg.Properties["FullName"]); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment