Search in sources :

Example 1 with RemotingException

use of org.apache.rocketmq.remoting.exception.RemotingException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtImpl method messageTrackDetail.

@Override
public List<MessageTrack> messageTrackDetail(MessageExt msg) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    List<MessageTrack> result = new ArrayList<MessageTrack>();
    GroupList groupList = this.queryTopicConsumeByWho(msg.getTopic());
    for (String group : groupList.getGroupList()) {
        MessageTrack mt = new MessageTrack();
        mt.setConsumerGroup(group);
        mt.setTrackType(TrackType.UNKNOWN);
        ConsumerConnection cc = null;
        try {
            cc = this.examineConsumerConnectionInfo(group);
        } catch (MQBrokerException e) {
            if (ResponseCode.CONSUMER_NOT_ONLINE == e.getResponseCode()) {
                mt.setTrackType(TrackType.NOT_ONLINE);
            }
            mt.setExceptionDesc("CODE:" + e.getResponseCode() + " DESC:" + e.getErrorMessage());
            result.add(mt);
            continue;
        } catch (Exception e) {
            mt.setExceptionDesc(RemotingHelper.exceptionSimpleDesc(e));
            result.add(mt);
            continue;
        }
        switch(cc.getConsumeType()) {
            case CONSUME_ACTIVELY:
                mt.setTrackType(TrackType.PULL);
                break;
            case CONSUME_PASSIVELY:
                boolean ifConsumed = false;
                try {
                    ifConsumed = this.consumed(msg, group);
                } catch (MQClientException e) {
                    if (ResponseCode.CONSUMER_NOT_ONLINE == e.getResponseCode()) {
                        mt.setTrackType(TrackType.NOT_ONLINE);
                    }
                    mt.setExceptionDesc("CODE:" + e.getResponseCode() + " DESC:" + e.getErrorMessage());
                    result.add(mt);
                    continue;
                } catch (MQBrokerException e) {
                    if (ResponseCode.CONSUMER_NOT_ONLINE == e.getResponseCode()) {
                        mt.setTrackType(TrackType.NOT_ONLINE);
                    }
                    mt.setExceptionDesc("CODE:" + e.getResponseCode() + " DESC:" + e.getErrorMessage());
                    result.add(mt);
                    continue;
                } catch (Exception e) {
                    mt.setExceptionDesc(RemotingHelper.exceptionSimpleDesc(e));
                    result.add(mt);
                    continue;
                }
                if (ifConsumed) {
                    mt.setTrackType(TrackType.CONSUMED);
                    Iterator<Entry<String, SubscriptionData>> it = cc.getSubscriptionTable().entrySet().iterator();
                    while (it.hasNext()) {
                        Entry<String, SubscriptionData> next = it.next();
                        if (next.getKey().equals(msg.getTopic())) {
                            if (next.getValue().getTagsSet().contains(msg.getTags()) || next.getValue().getTagsSet().contains("*") || next.getValue().getTagsSet().isEmpty()) {
                            } else {
                                mt.setTrackType(TrackType.CONSUMED_BUT_FILTERED);
                            }
                        }
                    }
                } else {
                    mt.setTrackType(TrackType.NOT_CONSUME_YET);
                }
                break;
            default:
                break;
        }
        result.add(mt);
    }
    return result;
}
Also used : MessageTrack(org.apache.rocketmq.tools.admin.api.MessageTrack) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) ArrayList(java.util.ArrayList) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) MQClientException(org.apache.rocketmq.client.exception.MQClientException) RemotingConnectException(org.apache.rocketmq.remoting.exception.RemotingConnectException) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) Entry(java.util.Map.Entry) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 2 with RemotingException

use of org.apache.rocketmq.remoting.exception.RemotingException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class QueryMsgByIdSubCommand method sendMsg.

private void sendMsg(final DefaultMQAdminExt defaultMQAdminExt, final DefaultMQProducer defaultMQProducer, final String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    try {
        MessageExt msg = defaultMQAdminExt.viewMessage(msgId);
        if (msg != null) {
            // resend msg by id
            System.out.printf("prepare resend msg. originalMsgId=" + msgId);
            SendResult result = defaultMQProducer.send(msg);
            System.out.printf("%s", result);
        } else {
            System.out.printf("no message. msgId=" + msgId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) SendResult(org.apache.rocketmq.client.producer.SendResult) IOException(java.io.IOException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 3 with RemotingException

use of org.apache.rocketmq.remoting.exception.RemotingException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class QueryMsgByUniqueKeySubCommand method queryById.

public static void queryById(final DefaultMQAdminExt admin, final String topic, final String msgId) throws MQClientException, RemotingException, MQBrokerException, InterruptedException, IOException {
    MessageExt msg = admin.viewMessage(topic, msgId);
    String bodyTmpFilePath = createBodyFile(msg);
    System.out.printf("%-20s %s%n", "Topic:", msg.getTopic());
    System.out.printf("%-20s %s%n", "Tags:", "[" + msg.getTags() + "]");
    System.out.printf("%-20s %s%n", "Keys:", "[" + msg.getKeys() + "]");
    System.out.printf("%-20s %d%n", "Queue ID:", msg.getQueueId());
    System.out.printf("%-20s %d%n", "Queue Offset:", msg.getQueueOffset());
    System.out.printf("%-20s %d%n", "CommitLog Offset:", msg.getCommitLogOffset());
    System.out.printf("%-20s %d%n", "Reconsume Times:", msg.getReconsumeTimes());
    System.out.printf("%-20s %s%n", "Born Timestamp:", UtilAll.timeMillisToHumanString2(msg.getBornTimestamp()));
    System.out.printf("%-20s %s%n", "Store Timestamp:", UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp()));
    System.out.printf("%-20s %s%n", "Born Host:", RemotingHelper.parseSocketAddressAddr(msg.getBornHost()));
    System.out.printf("%-20s %s%n", "Store Host:", RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()));
    System.out.printf("%-20s %d%n", "System Flag:", msg.getSysFlag());
    System.out.printf("%-20s %s%n", "Properties:", msg.getProperties() != null ? msg.getProperties().toString() : "");
    System.out.printf("%-20s %s%n", "Message Body Path:", bodyTmpFilePath);
    try {
        List<MessageTrack> mtdList = admin.messageTrackDetail(msg);
        if (mtdList.isEmpty()) {
            System.out.printf("%n%nWARN: No Consumer");
        } else {
            System.out.printf("%n%n");
            for (MessageTrack mt : mtdList) {
                System.out.printf("%s", mt);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) MessageTrack(org.apache.rocketmq.tools.admin.api.MessageTrack) IOException(java.io.IOException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 4 with RemotingException

use of org.apache.rocketmq.remoting.exception.RemotingException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MonitorService method reportConsumerRunningInfo.

public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException, MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();
        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }
        try {
            ConsumerRunningInfo info = defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }
    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
Also used : Connection(org.apache.rocketmq.common.protocol.body.Connection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumerRunningInfo(org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo) TreeMap(java.util.TreeMap) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 5 with RemotingException

use of org.apache.rocketmq.remoting.exception.RemotingException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MonitorService method doMonitorWork.

public void doMonitorWork() throws RemotingException, MQClientException, InterruptedException {
    long beginTime = System.currentTimeMillis();
    this.monitorListener.beginRound();
    TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
    for (String topic : topicList.getTopicList()) {
        if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
            String consumerGroup = topic.substring(MixAll.RETRY_GROUP_TOPIC_PREFIX.length());
            try {
                this.reportUndoneMsgs(consumerGroup);
            } catch (Exception e) {
            // log.error("reportUndoneMsgs Exception", e);
            }
            try {
                this.reportConsumerRunningInfo(consumerGroup);
            } catch (Exception e) {
            // log.error("reportConsumerRunningInfo Exception", e);
            }
        }
    }
    this.monitorListener.endRound();
    long spentTimeMills = System.currentTimeMillis() - beginTime;
    log.info("Execute one round monitor work, spent timemills: {}", spentTimeMills);
}
Also used : TopicList(org.apache.rocketmq.common.protocol.body.TopicList) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Aggregations

RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)45 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)39 MQClientException (org.apache.rocketmq.client.exception.MQClientException)39 SendResult (org.apache.rocketmq.client.producer.SendResult)13 Message (org.apache.rocketmq.common.message.Message)13 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)13 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 RemotingConnectException (org.apache.rocketmq.remoting.exception.RemotingConnectException)9 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)8 Test (org.junit.Test)8 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)7 RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)7 IOException (java.io.IOException)6 SendMessageContext (org.apache.rocketmq.client.hook.SendMessageContext)6 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)6 SendMessageRequestHeader (org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader)6 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)6 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)6 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)6 MessageExt (org.apache.rocketmq.common.message.MessageExt)5