我尝试按照1上的给定教程进行操作。我创建了一个主题,主题有2个订阅,分别使用sqlFilter(user_age< 50)和(user_age> = 50)。我有一个自定义属性user_age定义消息。 但是当我发送关于该主题的消息时,两个订阅都收到相同的消息,这是无稽之谈! 任何的想法?
我的代码完全受到tuto中给出的启发,除了我使用此代码接收来自给定订阅的消息:
resultQM = service.receiveSubscriptionMessage("MyTopic", subName, opts);
答案 0 :(得分: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");