From 1562bd0d11fbf4bbbca38921c6cc07ebe11ea15a Mon Sep 17 00:00:00 2001 From: shroman Date: Mon, 9 Jan 2017 16:28:10 +0800 Subject: [PATCH] [ROCKETMQ-30] Fixed method signature for Message Filter example and class loading from resources, closes apache/incubator-rocketmq#27 --- .../java/org/apache/rocketmq/example/filter/Consumer.java | 8 ++++++-- example/src/main/resources/MessageFilterImpl.java | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java index 7b79b370..d63435b5 100644 --- a/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.example.filter; +import java.io.File; import java.util.List; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; @@ -30,8 +31,11 @@ public class Consumer { public static void main(String[] args) throws InterruptedException, MQClientException { DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4"); - String filterCode = MixAll.file2String("/home/admin/MessageFilterImpl.java"); - consumer.subscribe("TopicFilter7", "org.apache.rocketmq.example.filter.MessageFilterImpl", + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + File classFile = new File(classLoader.getResource("MessageFilterImpl.java").getFile()); + + String filterCode = MixAll.file2String(classFile); + consumer.subscribe("TopicTest", "org.apache.rocketmq.example.filter.MessageFilterImpl", filterCode); consumer.registerMessageListener(new MessageListenerConcurrently() { diff --git a/example/src/main/resources/MessageFilterImpl.java b/example/src/main/resources/MessageFilterImpl.java index 83ca00ef..23e4a79b 100644 --- a/example/src/main/resources/MessageFilterImpl.java +++ b/example/src/main/resources/MessageFilterImpl.java @@ -17,13 +17,14 @@ package org.apache.rocketmq.example.filter; +import org.apache.rocketmq.common.filter.FilterContext; import org.apache.rocketmq.common.filter.MessageFilter; import org.apache.rocketmq.common.message.MessageExt; public class MessageFilterImpl implements MessageFilter { @Override - public boolean match(MessageExt msg) { + public boolean match(MessageExt msg, FilterContext context) { String property = msg.getProperty("SequenceId"); if (property != null) { int id = Integer.parseInt(property); -- GitLab