RocketMQ supports the syntax specification of SQL92, but when message filter is used, messages cannot be filtered normally.

//The signature method of DefaultMQPushConsumer uses MessageFilter to implement class filtering of messages
public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException {

The PushConsumer is as follows:

 * java -cp .:lib/* demo.rocketmq.consumer.PushConsumerDemo1 g1<br>
public class PushConsumerDemo1 {
    public static void main(String[] args) throws MQClientException, IOException {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(args[0]);

        //Location of last consumption

        //This method is no longer supported. After 4.3.0, only MessageSelector.bySql filtering is supported.
        consumer.subscribe("TopicTest", "demo.rocketmq.consumer.TimestampMessageFilter"
                , MixAll.file2String("/usr/local/rocketmq/rocketmq-all-4.4.0/distribution/target/apache-rocketmq/demo-tom/lib/"));

        consumer.registerMessageListener(new MessageListenerConcurrently() {
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
                System.out.printf("%s Receive New Messages: %s %n", Thread.currentThread().getName(), msgs);
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;


        Runtime.getRuntime().addShutdownHook(new Thread(() -> consumer.shutdown()));

MessageFilter implementation class:

public class TimestampMessageFilter implements MessageFilter {
    public boolean match(MessageExt msg, FilterContext context) {
        Long t = Long.parseLong(msg.getUserProperty("timestamp"));
        System.out.println("MessageFilter msg timestamp : " + t);
        if (t <= System.currentTimeMillis()) {
            return true;
        return false;

RocketMQ logs are as follows:


2019-07-10 09:45:07,007 WARN RocketmqClient - register message class filter failed, because no filter server, ConsumerGroup: g1 Topic: TopicTest ClassName: demo.rocketmq.consumer.TimestampMessageFilter
2019-07-10 09:45:09,009 ERROR RocketmqClient - pullKernelImpl exception
org.apache.rocketmq.client.exception.MQClientException: Find Filter Server Failed, Broker Addr: topic: TopicTest
For more information, please visit the url,
        at org.apache.rocketmq.client.impl.consumer.PullAPIWrapper.computPullFromWhichFilterServer(
        at org.apache.rocketmq.client.impl.consumer.PullAPIWrapper.pullKernelImpl(
        at org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl.pullMessage(
        at org.apache.rocketmq.client.impl.consumer.PullMessageService.pullMessage(


2019-07-11 17:27:22 INFO FilterServerManagerScheduledThread1 - CallShell: <sh /usr/local/rocketmq/rocketmq-all-4.4.0/distribution/target/apache-rocketmq/bin/ -c conf/2m-noslave/ -n localhost:9876> OK

Although the above CallShell did not report an error in the code, its execution was not successful, and the information in the log was a bit misleading. Since RocketMQ4.3, the classes related to FiltersrvStartup have been removed. Therefore, the filter service cannot be started as before.

OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Error: Could not find or load main class org.apache.rocketmq.filtersrv.FiltersrvStartup

An example is given in the Filter document on the official website: sql92

The method given in the example is to filter in the form of MessageSelector. At present (> = 4.3.0) it should no longer support the filtering in the form of MessageFilter. Whether it will be abolished or implemented in other ways in the future remains to be seen.

Attachment: the following forms of filtration are available:

 * java -cp .:lib/* demo.rocketmq.consumer.PullConsumerDemo1 g1
 * Pull mode: the client actively pulls messages.
public class PullConsumerDemo1 {
    public static void main(String[] args) throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(args[0]);

        Runtime.getRuntime().addShutdownHook(new Thread(() -> consumer.shutdown()));

        MessageQueue mq = new MessageQueue("TopicTest", "broker-a", 1);
        long offset = 0;
        //Note: sql filtering in the Pull mode is only supported in 4.4.0, and it was supported before the Push mode.
        PullResult result = consumer.pull(mq, MessageSelector.bySql("timestamp <= " + System.currentTimeMillis()),
                offset, 3);
        while (true) {
            offset = result.getNextBeginOffset();
            System.out.printf("Pull Result: %s, next offset: %s %n", result.getPullStatus(), offset);
            if (result.getPullStatus() == PullStatus.FOUND) {
                List<MessageExt> list = result.getMsgFoundList();
                System.out.printf("Pull Messages: %d ,content: %s %n", list.size(), list);
            } else {
                System.out.println("Sleep 10s..");
            result = consumer.pull(mq, MessageSelector.bySql("timestamp <= " + System.currentTimeMillis()),
                    offset, 3);

MessageFilter related: issues452