use of org.apache.rocketmq.common.protocol.body.ConsumerConnection in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class GroupConsumeInfo method getMessageQueueAllocationResult.
private Map<MessageQueue, String> getMessageQueueAllocationResult(DefaultMQAdminExt defaultMQAdminExt, String groupName) {
Map<MessageQueue, String> results = new HashMap<>();
try {
ConsumerConnection consumerConnection = defaultMQAdminExt.examineConsumerConnectionInfo(groupName);
for (Connection connection : consumerConnection.getConnectionSet()) {
String clientId = connection.getClientId();
ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExt.getConsumerRunningInfo(groupName, clientId, false);
for (MessageQueue messageQueue : consumerRunningInfo.getMqTable().keySet()) {
results.put(messageQueue, clientId.split("@")[0]);
}
}
} catch (Exception ignore) {
}
return results;
}
use of org.apache.rocketmq.common.protocol.body.ConsumerConnection in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class ConsumerStatusSubCommand 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 {
defaultMQAdminExt.start();
String group = commandLine.getOptionValue('g').trim();
ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(group);
boolean jstack = commandLine.hasOption('s');
if (!commandLine.hasOption('i')) {
int i = 1;
long now = System.currentTimeMillis();
final TreeMap<String, ConsumerRunningInfo> /* clientId */
criTable = new TreeMap<String, ConsumerRunningInfo>();
for (Connection conn : cc.getConnectionSet()) {
try {
ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExt.getConsumerRunningInfo(group, conn.getClientId(), jstack);
if (consumerRunningInfo != null) {
criTable.put(conn.getClientId(), consumerRunningInfo);
String filePath = now + "/" + conn.getClientId();
MixAll.string2FileNotSafe(consumerRunningInfo.formatString(), filePath);
System.out.printf("%03d %-40s %-20s %s%n", i++, conn.getClientId(), MQVersion.getVersionDesc(conn.getVersion()), filePath);
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (!criTable.isEmpty()) {
boolean subSame = ConsumerRunningInfo.analyzeSubscription(criTable);
boolean rebalanceOK = subSame && ConsumerRunningInfo.analyzeRebalance(criTable);
if (subSame) {
System.out.printf("%n%nSame subscription in the same group of consumer");
System.out.printf("%n%nRebalance %s%n", rebalanceOK ? "OK" : "Failed");
Iterator<Entry<String, ConsumerRunningInfo>> it = criTable.entrySet().iterator();
while (it.hasNext()) {
Entry<String, ConsumerRunningInfo> next = it.next();
String result = ConsumerRunningInfo.analyzeProcessQueue(next.getKey(), next.getValue());
if (result.length() > 0) {
System.out.printf(result);
}
}
} else {
System.out.printf("%n%nWARN: Different subscription in the same group of consumer!!!");
}
}
} else {
String clientId = commandLine.getOptionValue('i').trim();
ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExt.getConsumerRunningInfo(group, clientId, jstack);
if (consumerRunningInfo != null) {
System.out.printf("%s", consumerRunningInfo.formatString());
}
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.common.protocol.body.ConsumerConnection in project rocketmq by apache.
the class MQClientAPIImpl method getConsumerConnectionList.
public ConsumerConnection getConsumerConnectionList(final String addr, final String consumerGroup, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException {
GetConsumerConnectionListRequestHeader requestHeader = new GetConsumerConnectionListRequestHeader();
requestHeader.setConsumerGroup(consumerGroup);
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_CONNECTION_LIST, requestHeader);
RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
switch(response.getCode()) {
case ResponseCode.SUCCESS:
{
return ConsumerConnection.decode(response.getBody(), ConsumerConnection.class);
}
default:
break;
}
throw new MQBrokerException(response.getCode(), response.getRemark());
}
use of org.apache.rocketmq.common.protocol.body.ConsumerConnection in project rocketmq by apache.
the class AdminBrokerProcessor method getConsumerConnectionList.
private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
final GetConsumerConnectionListRequestHeader requestHeader = (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class);
ConsumerGroupInfo consumerGroupInfo = this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup());
if (consumerGroupInfo != null) {
ConsumerConnection bodydata = new ConsumerConnection();
bodydata.setConsumeFromWhere(consumerGroupInfo.getConsumeFromWhere());
bodydata.setConsumeType(consumerGroupInfo.getConsumeType());
bodydata.setMessageModel(consumerGroupInfo.getMessageModel());
bodydata.getSubscriptionTable().putAll(consumerGroupInfo.getSubscriptionTable());
Iterator<Map.Entry<Channel, ClientChannelInfo>> it = consumerGroupInfo.getChannelInfoTable().entrySet().iterator();
while (it.hasNext()) {
ClientChannelInfo info = it.next().getValue();
Connection connection = new Connection();
connection.setClientId(info.getClientId());
connection.setLanguage(info.getLanguage());
connection.setVersion(info.getVersion());
connection.setClientAddr(RemotingHelper.parseChannelRemoteAddr(info.getChannel()));
bodydata.getConnectionSet().add(connection);
}
byte[] body = bodydata.encode();
response.setBody(body);
response.setCode(ResponseCode.SUCCESS);
response.setRemark(null);
return response;
}
response.setCode(ResponseCode.CONSUMER_NOT_ONLINE);
response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] not online");
return response;
}
use of org.apache.rocketmq.common.protocol.body.ConsumerConnection in project rocketmq by apache.
the class MonitorService method reportUndoneMsgs.
private void reportUndoneMsgs(final String consumerGroup) {
ConsumeStats cs = null;
try {
cs = defaultMQAdminExt.examineConsumeStats(consumerGroup);
} catch (Exception e) {
return;
}
ConsumerConnection cc = null;
try {
cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
} catch (Exception e) {
return;
}
if (cs != null) {
HashMap<String, ConsumeStats> /* Topic */
csByTopic = new HashMap<String, ConsumeStats>();
{
Iterator<Entry<MessageQueue, OffsetWrapper>> it = cs.getOffsetTable().entrySet().iterator();
while (it.hasNext()) {
Entry<MessageQueue, OffsetWrapper> next = it.next();
MessageQueue mq = next.getKey();
OffsetWrapper ow = next.getValue();
ConsumeStats csTmp = csByTopic.get(mq.getTopic());
if (null == csTmp) {
csTmp = new ConsumeStats();
csByTopic.put(mq.getTopic(), csTmp);
}
csTmp.getOffsetTable().put(mq, ow);
}
}
{
Iterator<Entry<String, ConsumeStats>> it = csByTopic.entrySet().iterator();
while (it.hasNext()) {
Entry<String, ConsumeStats> next = it.next();
UndoneMsgs undoneMsgs = new UndoneMsgs();
undoneMsgs.setConsumerGroup(consumerGroup);
undoneMsgs.setTopic(next.getKey());
this.computeUndoneMsgs(undoneMsgs, next.getValue());
this.monitorListener.reportUndoneMsgs(undoneMsgs);
this.reportFailedMsgs(consumerGroup, next.getKey());
}
}
}
}
Aggregations