Java Code Examples for com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer#setInstanceName()
The following examples show how to use
com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer#setInstanceName() .
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: MQHelper.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
/** * 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(); } }
Example 2
Source File: MQHelper.java From rocketmq with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example 3
Source File: MQHelper.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example 4
Source File: QueryMsgByOffsetSubCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
@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(); } }
Example 5
Source File: MessageService.java From rocketmq with Apache License 2.0 | 4 votes |
@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; }
Example 6
Source File: QueryMsgByOffsetSubCommand.java From rocketmq with Apache License 2.0 | 4 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP,rpcHook); 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(); } }
Example 7
Source File: QueryMsgByOffsetSubCommand.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
@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(); } }