Search in sources :

Example 61 with MQBrokerException

use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class StatsAllSubCommand method printTopicDetail.

public static void printTopicDetail(final DefaultMQAdminExt admin, final String topic, final boolean activeTopic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicRouteData topicRouteData = admin.examineTopicRouteInfo(topic);
    GroupList groupList = admin.queryTopicConsumeByWho(topic);
    double inTPS = 0;
    long inMsgCntToday = 0;
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
        if (masterAddr != null) {
            try {
                BrokerStatsData bsd = admin.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic);
                inTPS += bsd.getStatsMinute().getTps();
                inMsgCntToday += compute24HourSum(bsd);
            } catch (Exception e) {
            }
        }
    }
    if (groupList != null && !groupList.getGroupList().isEmpty()) {
        for (String group : groupList.getGroupList()) {
            double outTPS = 0;
            long outMsgCntToday = 0;
            for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (masterAddr != null) {
                    try {
                        String statsKey = String.format("%s@%s", topic, group);
                        BrokerStatsData bsd = admin.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey);
                        outTPS += bsd.getStatsMinute().getTps();
                        outMsgCntToday += compute24HourSum(bsd);
                    } catch (Exception e) {
                    }
                }
            }
            long accumulate = 0;
            try {
                ConsumeStats consumeStats = admin.examineConsumeStats(group, topic);
                if (consumeStats != null) {
                    accumulate = consumeStats.computeTotalDiff();
                    if (accumulate < 0) {
                        accumulate = 0;
                    }
                }
            } catch (Exception e) {
            }
            if (!activeTopic || (inMsgCntToday > 0) || (outMsgCntToday > 0)) {
                // 第二个参数默认是32,有时候消费者长度过长显示不去,修改为52
                System.out.printf("%-32s  %-52s %12d %11.2f %11.2f %14d %14d%n", UtilAll.frontStringAtLeast(topic, 32), // 有时候消费者长度过长显示不去,修改为52
                UtilAll.frontStringAtLeast(group, 52), accumulate, inTPS, outTPS, inMsgCntToday, outMsgCntToday);
            }
        }
    } else {
        if (!activeTopic || (inMsgCntToday > 0)) {
            // 第二个参数默认是32,有时候消费者长度过长显示不去,修改为52
            System.out.printf("%-32s  %-52s %12d %11.2f %11s %14d %14s%n", UtilAll.frontStringAtLeast(topic, 52), "", 0, inTPS, "", inMsgCntToday, "NO_CONSUMER");
        }
    }
}
Also used : GroupList(org.apache.rocketmq.common.protocol.body.GroupList) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) 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) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData)

Example 62 with MQBrokerException

use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class Producer method main.

public static void main(String[] args) throws UnsupportedEncodingException {
    try {
        MQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
        producer.start();
        String[] tags = new String[] { "TagA", "TagB", "TagC", "TagD", "TagE" };
        for (int i = 0; i < 100; i++) {
            int orderId = i % 10;
            Message msg = new Message("TopicTestjjj", tags[i % tags.length], "KEY" + i, ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
            SendResult sendResult = producer.send(msg, new MessageQueueSelector() {

                @Override
                public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
                    Integer id = (Integer) arg;
                    int index = id % mqs.size();
                    return mqs.get(index);
                }
            }, orderId);
            System.out.printf("%s%n", sendResult);
        }
        producer.shutdown();
    } catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Message(org.apache.rocketmq.common.message.Message) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) MQProducer(org.apache.rocketmq.client.producer.MQProducer) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) MessageQueueSelector(org.apache.rocketmq.client.producer.MessageQueueSelector) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) SendResult(org.apache.rocketmq.client.producer.SendResult) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 63 with MQBrokerException

use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BrokerOuterAPI method getAllSubscriptionGroupConfig.

public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
    RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper)

Example 64 with MQBrokerException

use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BrokerOuterAPI method getAllTopicConfig.

public TopicConfigSerializeWrapper getAllTopicConfig(final String addr) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(true, addr), request, 3000);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                return TopicConfigSerializeWrapper.decode(response.getBody(), TopicConfigSerializeWrapper.class);
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) TopicConfigSerializeWrapper(org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper)

Example 65 with MQBrokerException

use of org.apache.rocketmq.client.exception.MQBrokerException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BrokerOuterAPI method getAllConsumerOffset.

public ConsumerOffsetSerializeWrapper getAllConsumerOffset(final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_CONSUMER_OFFSET, null);
    RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                return ConsumerOffsetSerializeWrapper.decode(response.getBody(), ConsumerOffsetSerializeWrapper.class);
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ConsumerOffsetSerializeWrapper(org.apache.rocketmq.common.protocol.body.ConsumerOffsetSerializeWrapper) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException)

Aggregations

MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)116 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)70 MQClientException (org.apache.rocketmq.client.exception.MQClientException)40 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)35 Message (org.apache.rocketmq.common.message.Message)12 SendResult (org.apache.rocketmq.client.producer.SendResult)11 RemotingConnectException (org.apache.rocketmq.remoting.exception.RemotingConnectException)11 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)11 UnsupportedEncodingException (java.io.UnsupportedEncodingException)10 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)10 RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)9 Test (org.junit.Test)9 MessageExt (org.apache.rocketmq.common.message.MessageExt)8 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)6 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)6 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)6 GroupList (org.apache.rocketmq.common.protocol.body.GroupList)6 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)6 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)6 IOException (java.io.IOException)5