该教程中的代码无法正常工作。这是我用来创建两个订阅(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");