Question

I try to follow the given tutorial at 1. I've created one topic with 2 subscriptions on the topics, respectively with the sqlFilter (user_age < 50) and (user_age>= 50). I've a custom property user_age define for messages. But when I send messages on the topic, both subscriptions receive the same messages which is nonsense! Any idea?

My code is fully inspired from the one given in the tuto, in the exception that I use this code to receive a message from a given subscription:

resultQM = service.receiveSubscriptionMessage("MyTopic", subName, opts);
Was it helpful?

Solution

The code in that tutorial does not work correctly. Here is the Java code I used to create two subscriptions (LowMessages and HighMessages) that actually filter on the value of a user-defined custom property "MessageNumber". I found this works. Note you need to explicitly give ruleInfo a name ("RULENAME") and you also need to explicitly delete the default "AllMatch" rule for the subscription (or you get no filtering.)

  SubscriptionInfo subInfo = new SubscriptionInfo("LowMessages");
  CreateSubscriptionResult result = service.createSubscription("TestTopic", subInfo);
  RuleInfo ruleInfo = new RuleInfo("RULENAME");
  ruleInfo = ruleInfo.withSqlExpressionFilter("MessageNumber <= 3");
  CreateRuleResult ruleResult = service.createRule("TestTopic", "LowMessages", ruleInfo);
  service.deleteRule("TestTopic", "LowMessages", "$Default");

  SubscriptionInfo subInfo2 = new SubscriptionInfo("HighMessages");
  CreateSubscriptionResult result2 = service.createSubscription("TestTopic", subInfo2);
  RuleInfo ruleInfo2 = new RuleInfo("RULENAME2");
  ruleInfo2 = ruleInfo2.withSqlExpressionFilter("MessageNumber > 3");
  CreateRuleResult ruleResult2 = service.createRule("TestTopic", "HighMessages", ruleInfo2);
  service.deleteRule("TestTopic", "HighMessages", "$Default");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top