use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class DecodeMessageIdCommond method execute.
@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException {
String messageId = commandLine.getOptionValue('i').trim();
try {
System.out.printf("ip=%s", MessageClientIDSetter.getIPStrFromID(messageId));
} catch (Exception e) {
e.printStackTrace();
}
try {
String date = UtilAll.formatDate(MessageClientIDSetter.getNearlyTimeFromID(messageId), UtilAll.YYYY_MM_DD_HH_MM_SS_SSS);
System.out.printf("date=%s", date);
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class PrintMessageByQueueCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP, rpcHook);
try {
String charsetName = !commandLine.hasOption('c') ? "UTF-8" : commandLine.getOptionValue('c').trim();
boolean printMsg = commandLine.hasOption('p') && Boolean.parseBoolean(commandLine.getOptionValue('p').trim());
boolean printBody = commandLine.hasOption('d') && Boolean.parseBoolean(commandLine.getOptionValue('d').trim());
boolean calByTag = commandLine.hasOption('f') && Boolean.parseBoolean(commandLine.getOptionValue('f').trim());
String subExpression = !commandLine.hasOption('s') ? "*" : commandLine.getOptionValue('s').trim();
String topic = commandLine.getOptionValue('t').trim();
String brokerName = commandLine.getOptionValue('a').trim();
int queueId = Integer.parseInt(commandLine.getOptionValue('i').trim());
consumer.start();
MessageQueue mq = new MessageQueue(topic, brokerName, queueId);
long minOffset = consumer.minOffset(mq);
long maxOffset = consumer.maxOffset(mq);
if (commandLine.hasOption('b')) {
String timestampStr = commandLine.getOptionValue('b').trim();
long timeValue = timestampFormat(timestampStr);
minOffset = consumer.searchOffset(mq, timeValue);
}
if (commandLine.hasOption('e')) {
String timestampStr = commandLine.getOptionValue('e').trim();
long timeValue = timestampFormat(timestampStr);
maxOffset = consumer.searchOffset(mq, timeValue);
}
final Map<String, AtomicLong> tagCalmap = new HashMap<String, AtomicLong>();
READQ: for (long offset = minOffset; offset < maxOffset; ) {
try {
PullResult pullResult = consumer.pull(mq, subExpression, offset, 32);
offset = pullResult.getNextBeginOffset();
switch(pullResult.getPullStatus()) {
case FOUND:
calculateByTag(pullResult.getMsgFoundList(), tagCalmap, calByTag);
printMessage(pullResult.getMsgFoundList(), charsetName, printMsg, printBody);
break;
case NO_MATCHED_MSG:
case NO_NEW_MSG:
case OFFSET_ILLEGAL:
break READQ;
}
} catch (Exception e) {
e.printStackTrace();
break;
}
}
printCalculateByTag(tagCalmap, calByTag);
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
consumer.shutdown();
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class PrintMessageSubCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP, rpcHook);
try {
String topic = commandLine.getOptionValue('t').trim();
String charsetName = !commandLine.hasOption('c') ? "UTF-8" : commandLine.getOptionValue('c').trim();
String subExpression = !commandLine.hasOption('s') ? "*" : commandLine.getOptionValue('s').trim();
boolean printBody = !commandLine.hasOption('d') || Boolean.parseBoolean(commandLine.getOptionValue('d').trim());
consumer.start();
Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues(topic);
for (MessageQueue mq : mqs) {
long minOffset = consumer.minOffset(mq);
long maxOffset = consumer.maxOffset(mq);
if (commandLine.hasOption('b')) {
String timestampStr = commandLine.getOptionValue('b').trim();
long timeValue = timestampFormat(timestampStr);
minOffset = consumer.searchOffset(mq, timeValue);
}
if (commandLine.hasOption('e')) {
String timestampStr = commandLine.getOptionValue('e').trim();
long timeValue = timestampFormat(timestampStr);
maxOffset = consumer.searchOffset(mq, timeValue);
}
System.out.printf("minOffset=%s, maxOffset=%s, %s", minOffset, maxOffset, mq);
READQ: for (long offset = minOffset; offset < maxOffset; ) {
try {
PullResult pullResult = consumer.pull(mq, subExpression, offset, 32);
offset = pullResult.getNextBeginOffset();
switch(pullResult.getPullStatus()) {
case FOUND:
printMessage(pullResult.getMsgFoundList(), charsetName, printBody);
break;
case NO_MATCHED_MSG:
System.out.printf(mq + " no matched msg. status=%s, offset=%s", pullResult.getPullStatus(), offset);
break;
case NO_NEW_MSG:
case OFFSET_ILLEGAL:
System.out.printf(mq + " print msg finished. status=%s, offset=%s", pullResult.getPullStatus(), offset);
break READQ;
}
} catch (Exception e) {
e.printStackTrace();
break;
}
}
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
consumer.shutdown();
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class QueryMsgByIdSubCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
DefaultMQProducer defaultMQProducer = new DefaultMQProducer("ReSendMsgById");
defaultMQProducer.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
defaultMQAdminExt.start();
if (commandLine.hasOption('s')) {
if (commandLine.hasOption('u')) {
String unitName = commandLine.getOptionValue('u').trim();
defaultMQProducer.setUnitName(unitName);
}
defaultMQProducer.start();
}
final String msgIds = commandLine.getOptionValue('i').trim();
final String[] msgIdArr = StringUtils.split(msgIds, ",");
if (commandLine.hasOption('g') && commandLine.hasOption('d')) {
final String consumerGroup = commandLine.getOptionValue('g').trim();
final String clientId = commandLine.getOptionValue('d').trim();
for (String msgId : msgIdArr) {
if (StringUtils.isNotBlank(msgId)) {
pushMsg(defaultMQAdminExt, consumerGroup, clientId, msgId.trim());
}
}
} else if (commandLine.hasOption('s')) {
boolean resend = Boolean.parseBoolean(commandLine.getOptionValue('s', "false").trim());
if (resend) {
for (String msgId : msgIdArr) {
if (StringUtils.isNotBlank(msgId)) {
sendMsg(defaultMQAdminExt, defaultMQProducer, msgId.trim());
}
}
}
} else {
for (String msgId : msgIdArr) {
if (StringUtils.isNotBlank(msgId)) {
queryById(defaultMQAdminExt, msgId.trim());
}
}
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQProducer.shutdown();
defaultMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class QueryMsgByKeySubCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
final String topic = commandLine.getOptionValue('t').trim();
final String key = commandLine.getOptionValue('k').trim();
this.queryByKey(defaultMQAdminExt, topic, key);
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
Aggregations