Skip to content

Commit

Permalink
[ROCKETMQ-30] Fixed method signature for Message Filter example and c…
Browse files Browse the repository at this point in the history
…lass loading from resources, closes apache#27
  • Loading branch information
shroman authored and zhouxinyu committed Jan 9, 2017
1 parent f936057 commit 1562bd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion example/src/main/resources/MessageFilterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1562bd0

Please sign in to comment.