当前位置: 首页>>代码示例>>Java>>正文


Java DefaultMQPullConsumer.shutdown方法代码示例

本文整理汇总了Java中com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMQPullConsumer.shutdown方法的具体用法?Java DefaultMQPullConsumer.shutdown怎么用?Java DefaultMQPullConsumer.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer的用法示例。


在下文中一共展示了DefaultMQPullConsumer.shutdown方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");
    consumer.start();

    try {
        MessageQueue mq = new MessageQueue();
        mq.setQueueId(0);
        mq.setTopic("TopicTest3");
        mq.setBrokerName("vivedeMacBook-Pro.local");

        long offset = 26;

        long beginTime = System.currentTimeMillis();
        PullResult pullResult = consumer.pullBlockIfNotFound(mq, null, offset, 32);
        System.out.println(System.currentTimeMillis() - beginTime);
        System.out.println(pullResult);
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    consumer.shutdown();
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:24,代码来源:PullConsumerTest.java

示例2: main

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");
    consumer.start();

    try {
        MessageQueue mq = new MessageQueue();
        mq.setQueueId(0);
        mq.setTopic("TopicTest3");
        mq.setBrokerName("vivedeMacBook-Pro.local");

        long offset = 26;

        long beginTime = System.currentTimeMillis();

        PullResult pullResult = consumer.pullBlockIfNotFound(mq, null, offset, 32);
        System.out.println(System.currentTimeMillis() - beginTime);
        System.out.println(pullResult);
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    consumer.shutdown();


}
 
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:27,代码来源:PullConsumerTest.java

示例3: resetOffsetByTimestamp

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
/**
 * Reset consumer topic offset according to time
 * 
 * @param messageModel
 *            which model
 * @param instanceName
 *            which instance
 * @param consumerGroup
 *            consumer group
 * @param topic
 *            topic
 * @param timestamp
 *            time
 * @throws Exception
 */
public static void resetOffsetByTimestamp(//
        final MessageModel messageModel,//
        final String instanceName,//
        final String consumerGroup, //
        final String topic, //
        final long timestamp) throws Exception {
    final Logger log = ClientLogger.getLog();

    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(consumerGroup);
    consumer.setInstanceName(instanceName);
    consumer.setMessageModel(messageModel);
    consumer.start();

    Set<MessageQueue> mqs = null;
    try {
        mqs = consumer.fetchSubscribeMessageQueues(topic);
        if (mqs != null && !mqs.isEmpty()) {
            TreeSet<MessageQueue> mqsNew = new TreeSet<MessageQueue>(mqs);
            for (MessageQueue mq : mqsNew) {
                long offset = consumer.searchOffset(mq, timestamp);
                if (offset >= 0) {
                    consumer.updateConsumeOffset(mq, offset);
                    log.info("resetOffsetByTimestamp updateConsumeOffset success, {} {} {}",
                        consumerGroup, offset, mq);
                }
            }
        }
    }
    catch (Exception e) {
        log.warn("resetOffsetByTimestamp Exception", e);
        throw e;
    }
    finally {
        if (mqs != null) {
            consumer.getDefaultMQPullConsumerImpl().getOffsetStore().persistAll(mqs);
        }
        consumer.shutdown();
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:55,代码来源:MQHelper.java

示例4: main

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");

    consumer.start();

    Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues("TopicTest1");
    for (MessageQueue mq : mqs) {
        System.out.println("Consume from the queue: " + mq);
        SINGLE_MQ: while (true) {
            try {
                PullResult pullResult =
                        consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32);
                System.out.println(pullResult);
                putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
                switch (pullResult.getPullStatus()) {
                case FOUND:
                    break;
                case NO_MATCHED_MSG:
                    break;
                case NO_NEW_MSG:
                    break SINGLE_MQ;
                case OFFSET_ILLEGAL:
                    break;
                default:
                    break;
                }
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    consumer.shutdown();
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:36,代码来源:PullConsumer.java

示例5: resetOffsetByTimestamp

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
/**
 * 根据时间戳来重置一个订阅组的消费进度
 * 
 * @param messageModel
 *            广播消费还是集群消费
 * @param instanceName
 *            实例名称,保持与工作Consumer一致。
 * @param consumerGroup
 *            订阅组
 * @param topic
 *            topic
 * @param timestamp
 *            时间戳
 * @throws Exception
 */
public static void resetOffsetByTimestamp(//
        final MessageModel messageModel,//
        final String instanceName,//
        final String consumerGroup, //
        final String topic, //
        final long timestamp) throws Exception {
    final Logger log = ClientLogger.getLog();

    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(consumerGroup);
    consumer.setInstanceName(instanceName);
    consumer.setMessageModel(messageModel);
    consumer.start();

    Set<MessageQueue> mqs = null;
    try {
        mqs = consumer.fetchSubscribeMessageQueues(topic);
        if (mqs != null && !mqs.isEmpty()) {
            TreeSet<MessageQueue> mqsNew = new TreeSet<MessageQueue>(mqs);
            for (MessageQueue mq : mqsNew) {
                long offset = consumer.searchOffset(mq, timestamp);
                if (offset >= 0) {
                    consumer.updateConsumeOffset(mq, offset);
                    log.info("resetOffsetByTimestamp updateConsumeOffset success, {} {} {}",
                        consumerGroup, offset, mq);
                }
            }
        }
    }
    catch (Exception e) {
        log.warn("resetOffsetByTimestamp Exception", e);
        throw e;
    }
    finally {
        if (mqs != null) {
            consumer.getDefaultMQPullConsumerImpl().getOffsetStore().persistAll(mqs);
        }
        consumer.shutdown();
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:55,代码来源:MQHelper.java

示例6: main

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");

    consumer.start();

    Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues("TopicTest");
    for (MessageQueue mq : mqs) {
        System.out.println("Consume from the queue: " + mq);
        SINGLE_MQ: while (true) {
            try {
                PullResult pullResult =
                        consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32);
                System.out.println(pullResult);
                putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
                switch (pullResult.getPullStatus()) {
                case FOUND:
                    // TODO
                    break;
                case NO_MATCHED_MSG:
                    break;
                case NO_NEW_MSG:
                    break SINGLE_MQ;
                case OFFSET_ILLEGAL:
                    break;
                default:
                    break;
                }
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    consumer.shutdown();
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:37,代码来源:PullConsumer.java

示例7: execute

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        //解析 sh mqadmin  queryMsgByOffset 命令携带的各种参数信息
        String topic = commandLine.getOptionValue('t').trim();
        String brokerName = commandLine.getOptionValue('b').trim();
        String queueId = commandLine.getOptionValue('i').trim();
        String offset = commandLine.getOptionValue('o').trim();

        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();
        defaultMQAdminExt.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
            case FOUND:
                QueryMsgByIdSubCommand.queryById(defaultMQAdminExt, pullResult.getMsgFoundList().get(0)
                    .getMsgId());
                break;
            case NO_MATCHED_MSG:
            case NO_NEW_MSG:
            case OFFSET_ILLEGAL:
            default:
                break;
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQPullConsumer.shutdown();
        defaultMQAdminExt.shutdown();
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:47,代码来源:QueryMsgByOffsetSubCommand.java

示例8: execute

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        String topic = commandLine.getOptionValue('t').trim();
        String brokerName = commandLine.getOptionValue('b').trim();
        String queueId = commandLine.getOptionValue('i').trim();
        String offset = commandLine.getOptionValue('o').trim();

        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();
        defaultMQAdminExt.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
            case FOUND:
                QueryMsgByIdSubCommand.queryById(defaultMQAdminExt, pullResult.getMsgFoundList().get(0)
                    .getMsgId());
                break;
            case NO_MATCHED_MSG:
            case NO_NEW_MSG:
            case OFFSET_ILLEGAL:
            default:
                break;
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQPullConsumer.shutdown();
        defaultMQAdminExt.shutdown();
    }
}
 
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:46,代码来源:QueryMsgByOffsetSubCommand.java

示例9: queryMsgByOffset

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
@CmdTrace(cmdClazz = QueryMsgByOffsetSubCommand.class)
public Table queryMsgByOffset(String topicName, String brokerName, String queueId, String offset)
        throws Throwable {
    Throwable t = null;
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP);

    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        MessageQueue mq = new MessageQueue();
        mq.setTopic(topicName);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
            case FOUND:
                Table table = queryMsgById(pullResult.getMsgFoundList().get(0).getMsgId());
                return table;
            case NO_MATCHED_MSG:
            case NO_NEW_MSG:
            case OFFSET_ILLEGAL:
            default:
                break;
            }
        }
        else {
            throw new IllegalStateException("pullResult is null");
        }
    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        defaultMQPullConsumer.shutdown();
    }
    throw t;
}
 
开发者ID:LXLun,项目名称:RocketMQMonitor,代码行数:43,代码来源:MessageService.java

示例10: execute

import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        String topic = commandLine.getOptionValue('t').trim();
        String brokerName = commandLine.getOptionValue('b').trim();
        String queueId = commandLine.getOptionValue('i').trim();
        String offset = commandLine.getOptionValue('o').trim();

        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
            case FOUND:
                QueryMsgByIdSubCommand.queryById(defaultMQAdminExt, pullResult.getMsgFoundList().get(0)
                    .getMsgId());
                break;
            case NO_MATCHED_MSG:
            case NO_NEW_MSG:
            case OFFSET_ILLEGAL:
            default:
                break;
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQPullConsumer.shutdown();
        defaultMQAdminExt.shutdown();
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:45,代码来源:QueryMsgByOffsetSubCommand.java


注:本文中的com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer.shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。