org.apache.rocketmq.client.consumer.PullTaskCallback Java Examples

The following examples show how to use org.apache.rocketmq.client.consumer.PullTaskCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PullScheduleService.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException {
    final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1");

    scheduleService.setMessageModel(MessageModel.CLUSTERING);
    scheduleService.registerPullTaskCallback("TopicTest1", new PullTaskCallback() {

        @Override
        public void doPullTask(MessageQueue mq, PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {

                long offset = consumer.fetchConsumeOffset(mq, false);
                if (offset < 0)
                    offset = 0;

                PullResult pullResult = consumer.pull(mq, "*", offset, 32);
                System.out.printf("%s%n", offset + "\t" + mq + "\t" + pullResult);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        break;
                    case NO_MATCHED_MSG:
                        break;
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                }
                consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset());

                context.setPullNextDelayTimeMillis(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    scheduleService.start();
}
 
Example #2
Source File: PullConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private void registerPullTaskCallback() {
    this.pullConsumerScheduleService.registerPullTaskCallback(targetQueueName, new PullTaskCallback() {
        @Override
        public void doPullTask(final MessageQueue mq, final PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {
                long offset = localMessageCache.nextPullOffset(mq);

                PullResult pullResult = consumer.pull(mq, "*",
                    offset, localMessageCache.nextPullBatchNums());
                ProcessQueue pq = rocketmqPullConsumer.getDefaultMQPullConsumerImpl().getRebalanceImpl()
                    .getProcessQueueTable().get(mq);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        if (pq != null) {
                            pq.putMessage(pullResult.getMsgFoundList());
                            for (final MessageExt messageExt : pullResult.getMsgFoundList()) {
                                localMessageCache.submitConsumeRequest(new ConsumeRequest(messageExt, mq, pq));
                            }
                        }
                        break;
                    default:
                        break;
                }
                localMessageCache.updatePullOffset(mq, pullResult.getNextBeginOffset());
            } catch (Exception e) {
                log.error("A error occurred in pull message process.", e);
            }
        }
    });
}
 
Example #3
Source File: PullScheduleService.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException {
    final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1");

    scheduleService.setMessageModel(MessageModel.CLUSTERING);
    scheduleService.registerPullTaskCallback("TopicTest", new PullTaskCallback() {

        @Override
        public void doPullTask(MessageQueue mq, PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {

                long offset = consumer.fetchConsumeOffset(mq, false);
                if (offset < 0)
                    offset = 0;

                PullResult pullResult = consumer.pull(mq, "*", offset, 32);
                System.out.printf("%s%n", offset + "\t" + mq + "\t" + pullResult);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        break;
                    case NO_MATCHED_MSG:
                        break;
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                }
                consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset());

                context.setPullNextDelayTimeMillis(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    scheduleService.start();
}
 
Example #4
Source File: PullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
private void registerPullTaskCallback(final String targetQueueName) {
    this.pullConsumerScheduleService.registerPullTaskCallback(targetQueueName, new PullTaskCallback() {
        @Override
        public void doPullTask(final MessageQueue mq, final PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {
                long offset = localMessageCache.nextPullOffset(mq);

                PullResult pullResult = consumer.pull(mq, "*",
                    offset, localMessageCache.nextPullBatchNums());
                ProcessQueue pq = rocketmqPullConsumer.getDefaultMQPullConsumerImpl().getRebalanceImpl()
                    .getProcessQueueTable().get(mq);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        if (pq != null) {
                            pq.putMessage(pullResult.getMsgFoundList());
                            for (final MessageExt messageExt : pullResult.getMsgFoundList()) {
                                localMessageCache.submitConsumeRequest(new ConsumeRequest(messageExt, mq, pq));
                            }
                        }
                        break;
                    default:
                        break;
                }
                localMessageCache.updatePullOffset(mq, pullResult.getNextBeginOffset());
            } catch (Exception e) {
                log.error("A error occurred in pull message process.", e);
            }
        }
    });
}
 
Example #5
Source File: PullConsumerImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
private void registerPullTaskCallback(final String targetQueueName) {
    this.pullConsumerScheduleService.registerPullTaskCallback(targetQueueName, new PullTaskCallback() {
        @Override
        public void doPullTask(final MessageQueue mq, final PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {
                long offset = localMessageCache.nextPullOffset(mq);

                PullResult pullResult = consumer.pull(mq, "*",
                    offset, localMessageCache.nextPullBatchNums());
                ProcessQueue pq = rocketmqPullConsumer.getDefaultMQPullConsumerImpl().getRebalanceImpl()
                    .getProcessQueueTable().get(mq);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        if (pq != null) {
                            pq.putMessage(pullResult.getMsgFoundList());
                            for (final MessageExt messageExt : pullResult.getMsgFoundList()) {
                                localMessageCache.submitConsumeRequest(new ConsumeRequest(messageExt, mq, pq));
                            }
                        }
                        break;
                    default:
                        break;
                }
                localMessageCache.updatePullOffset(mq, pullResult.getNextBeginOffset());
            } catch (Exception e) {
                log.error("A error occurred in pull message process.", e);
            }
        }
    });
}
 
Example #6
Source File: PullScheduleService.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException {
    final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1");

    scheduleService.setMessageModel(MessageModel.CLUSTERING);
    scheduleService.registerPullTaskCallback("TopicTest1", new PullTaskCallback() {

        @Override
        public void doPullTask(MessageQueue mq, PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {

                long offset = consumer.fetchConsumeOffset(mq, false);
                if (offset < 0)
                    offset = 0;

                PullResult pullResult = consumer.pull(mq, "*", offset, 32);
                System.out.printf("%s%n", offset + "\t" + mq + "\t" + pullResult);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        break;
                    case NO_MATCHED_MSG:
                        break;
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                }
                consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset());

                context.setPullNextDelayTimeMillis(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    scheduleService.start();
}
 
Example #7
Source File: PullScheduleService.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException {
    final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1");

    scheduleService.setMessageModel(MessageModel.CLUSTERING);
    scheduleService.registerPullTaskCallback("TopicTest1", new PullTaskCallback() {

        @Override
        public void doPullTask(MessageQueue mq, PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {

                long offset = consumer.fetchConsumeOffset(mq, false);
                if (offset < 0)
                    offset = 0;

                PullResult pullResult = consumer.pull(mq, "*", offset, 32);
                System.out.printf("%s%n", offset + "\t" + mq + "\t" + pullResult);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        break;
                    case NO_MATCHED_MSG:
                        break;
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                }
                consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset());

                context.setPullNextDelayTimeMillis(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    scheduleService.start();
}
 
Example #8
Source File: PullConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private void registerPullTaskCallback() {
    this.pullConsumerScheduleService.registerPullTaskCallback(targetQueueName, new PullTaskCallback() {
        @Override
        public void doPullTask(final MessageQueue mq, final PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {
                long offset = localMessageCache.nextPullOffset(mq);

                PullResult pullResult = consumer.pull(mq, "*",
                    offset, localMessageCache.nextPullBatchNums());
                ProcessQueue pq = rocketmqPullConsumer.getDefaultMQPullConsumerImpl().getRebalanceImpl()
                    .getProcessQueueTable().get(mq);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        if (pq != null) {
                            pq.putMessage(pullResult.getMsgFoundList());
                            for (final MessageExt messageExt : pullResult.getMsgFoundList()) {
                                localMessageCache.submitConsumeRequest(new ConsumeRequest(messageExt, mq, pq));
                            }
                        }
                        break;
                    default:
                        break;
                }
                localMessageCache.updatePullOffset(mq, pullResult.getNextBeginOffset());
            } catch (Exception e) {
                log.error("A error occurred in pull message process.", e);
            }
        }
    });
}
 
Example #9
Source File: PullScheduleService.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException {
    final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1");

    scheduleService.setMessageModel(MessageModel.CLUSTERING);
    scheduleService.registerPullTaskCallback("TopicTest1", new PullTaskCallback() {

        @Override
        public void doPullTask(MessageQueue mq, PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {

                long offset = consumer.fetchConsumeOffset(mq, false);
                if (offset < 0)
                    offset = 0;

                PullResult pullResult = consumer.pull(mq, "*", offset, 32);
                System.out.printf("%s%n", offset + "\t" + mq + "\t" + pullResult);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        break;
                    case NO_MATCHED_MSG:
                        break;
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                }
                consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset());

                context.setPullNextDelayTimeMillis(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    scheduleService.start();
}
 
Example #10
Source File: PullConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
private void registerPullTaskCallback() {
    this.pullConsumerScheduleService.registerPullTaskCallback(targetQueueName, new PullTaskCallback() {
        @Override
        public void doPullTask(final MessageQueue mq, final PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {
                long offset = localMessageCache.nextPullOffset(mq);

                PullResult pullResult = consumer.pull(mq, "*",
                    offset, localMessageCache.nextPullBatchNums());
                ProcessQueue pq = rocketmqPullConsumer.getDefaultMQPullConsumerImpl().getRebalanceImpl()
                    .getProcessQueueTable().get(mq);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        if (pq != null) {
                            pq.putMessage(pullResult.getMsgFoundList());
                            for (final MessageExt messageExt : pullResult.getMsgFoundList()) {
                                localMessageCache.submitConsumeRequest(new ConsumeRequest(messageExt, mq, pq));
                            }
                        }
                        break;
                    default:
                        break;
                }
                localMessageCache.updatePullOffset(mq, pullResult.getNextBeginOffset());
            } catch (Exception e) {
                log.error("A error occurred in pull message process.", e);
            }
        }
    });
}
 
Example #11
Source File: PullScheduleService.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException {
    final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1");

    scheduleService.setMessageModel(MessageModel.CLUSTERING);
    scheduleService.registerPullTaskCallback("TopicTest", new PullTaskCallback() {

        @Override
        public void doPullTask(MessageQueue mq, PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {

                long offset = consumer.fetchConsumeOffset(mq, false);
                if (offset < 0)
                    offset = 0;

                PullResult pullResult = consumer.pull(mq, "*", offset, 32);
                System.out.printf("%s%n", offset + "\t" + mq + "\t" + pullResult);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        break;
                    case NO_MATCHED_MSG:
                        break;
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                }
                consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset());

                context.setPullNextDelayTimeMillis(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    scheduleService.start();
}
 
Example #12
Source File: PullConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private void registerPullTaskCallback(final String targetQueueName) {
    this.pullConsumerScheduleService.registerPullTaskCallback(targetQueueName, new PullTaskCallback() {
        @Override
        public void doPullTask(final MessageQueue mq, final PullTaskContext context) {
            MQPullConsumer consumer = context.getPullConsumer();
            try {
                long offset = localMessageCache.nextPullOffset(mq);

                PullResult pullResult = consumer.pull(mq, "*",
                    offset, localMessageCache.nextPullBatchNums());
                ProcessQueue pq = rocketmqPullConsumer.getDefaultMQPullConsumerImpl().getRebalanceImpl()
                    .getProcessQueueTable().get(mq);
                switch (pullResult.getPullStatus()) {
                    case FOUND:
                        if (pq != null) {
                            pq.putMessage(pullResult.getMsgFoundList());
                            for (final MessageExt messageExt : pullResult.getMsgFoundList()) {
                                localMessageCache.submitConsumeRequest(new ConsumeRequest(messageExt, mq, pq));
                            }
                        }
                        break;
                    default:
                        break;
                }
                localMessageCache.updatePullOffset(mq, pullResult.getNextBeginOffset());
            } catch (Exception e) {
                log.error("An error occurred in pull message process.", e);
            }
        }
    });
}
 
Example #13
Source File: PullScheduleService.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws MQClientException {

        final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1");

        scheduleService.setMessageModel(MessageModel.CLUSTERING);
        scheduleService.registerPullTaskCallback("TopicTest", new PullTaskCallback() {

            @Override
            public void doPullTask(MessageQueue mq, PullTaskContext context) {
                MQPullConsumer consumer = context.getPullConsumer();
                try {

                    long offset = consumer.fetchConsumeOffset(mq, false);
                    if (offset < 0) {
                        offset = 0;
                    }

                    PullResult pullResult = consumer.pull(mq, "*", offset, 32);
                    System.out.printf("%s%n", offset + "\t" + mq + "\t" + pullResult);
                    switch (pullResult.getPullStatus()) {
                        case FOUND:
                            break;
                        case NO_MATCHED_MSG:
                            break;
                        case NO_NEW_MSG:
                        case OFFSET_ILLEGAL:
                            break;
                        default:
                            break;
                    }
                    consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset());

                    context.setPullNextDelayTimeMillis(100);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        scheduleService.start();
    }