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");
}
}
}
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();
}
}
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());
}
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());
}
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());
}
Aggregations