0

我尝试按照1给出的教程进行操作。我创建了一个主题,主题上有 2 个订阅,分别使用 sqlFilter (user_age < 50) 和 (user_age>= 50)。我为消息定义了一个自定义属性 user_age。但是当我发送关于该主题的消息时,两个订阅都会收到相同的消息,这是无稽之谈!任何的想法?

我的代码完全受教程中给出的启发,除了我使用此代码从给定订阅接收消息:

resultQM = service.receiveSubscriptionMessage("MyTopic", subName, opts);
4

1 回答 1

0

该教程中的代码无法正常工作。这是我用来创建两个订阅(LowMessages 和 HighMessages)的 Java 代码,它们实际上过滤了用户定义的自定义属性“MessageNumber”的值。我发现这行得通。请注意,您需要显式地为 ruleInfo 命名(“RULENAME”),并且您还需要显式删除订阅的默认“AllMatch”规则(否则您将无法过滤。)

  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");
于 2013-06-12T22:42:03.710 回答