use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.
the class CommandUtil method fetchBrokerNameByAddr.
public static String fetchBrokerNameByAddr(final MQAdminExt adminExt, final String addr) throws Exception {
ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo();
HashMap<String, BrokerData> /* brokerName */
brokerAddrTable = clusterInfoSerializeWrapper.getBrokerAddrTable();
Iterator<Map.Entry<String, BrokerData>> it = brokerAddrTable.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, BrokerData> entry = it.next();
HashMap<Long, String> brokerAddrs = entry.getValue().getBrokerAddrs();
if (brokerAddrs.containsValue(addr))
return entry.getKey();
}
throw new Exception("Make sure the specified broker addr exists or the nameserver which connected is correct.");
}
use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.
the class CommandUtil method fetchMasterAddrByClusterName.
public static Set<String> fetchMasterAddrByClusterName(final MQAdminExt adminExt, final String clusterName) throws InterruptedException, RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException, MQBrokerException {
Set<String> masterSet = new HashSet<String>();
ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo();
Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName);
if (brokerNameSet != null) {
for (String brokerName : brokerNameSet) {
BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
if (brokerData != null) {
String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
if (addr != null) {
masterSet.add(addr);
}
}
}
} else {
System.out.printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct.");
}
return masterSet;
}
use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.
the class DefaultMQAdminExtImpl method getTopicClusterList.
@Override
public Set<String> getTopicClusterList(final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException {
Set<String> clusterSet = new HashSet<String>();
ClusterInfo clusterInfo = examineBrokerClusterInfo();
TopicRouteData topicRouteData = examineTopicRouteInfo(topic);
BrokerData brokerData = topicRouteData.getBrokerDatas().get(0);
String brokerName = brokerData.getBrokerName();
Iterator<Map.Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Set<String>> next = it.next();
if (next.getValue().contains(brokerName)) {
clusterSet.add(next.getKey());
}
}
return clusterSet;
}
use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.
the class DefaultMQAdminExtImpl method examineProducerConnectionInfo.
@Override
public ProducerConnection examineProducerConnectionInfo(String producerGroup, final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
ProducerConnection result = new ProducerConnection();
List<BrokerData> brokers = this.examineTopicRouteInfo(topic).getBrokerDatas();
BrokerData brokerData = brokers.get(random.nextInt(brokers.size()));
String addr = null;
if (brokerData != null) {
addr = brokerData.selectBrokerAddr();
if (StringUtils.isNotBlank(addr)) {
result = this.mqClientInstance.getMQClientAPIImpl().getProducerConnectionList(addr, producerGroup, timeoutMillis);
}
}
if (result.getConnectionSet().isEmpty()) {
log.warn("the producer group not online. brokerAddr={}, group={}", addr, producerGroup);
throw new MQClientException("Not found the producer group connection", null);
}
return result;
}
use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.
the class DefaultMQAdminExtImpl method getConsumeStatus.
@Override
public Map<String, Map<MessageQueue, Long>> getConsumeStatus(String topic, String group, String clientAddr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
if (brokerDatas != null && brokerDatas.size() > 0) {
String addr = brokerDatas.get(0).selectBrokerAddr();
if (addr != null) {
return this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToGetConsumerStatus(addr, topic, group, clientAddr, timeoutMillis);
}
}
return Collections.EMPTY_MAP;
}
Aggregations