本文整理汇总了Java中org.apache.rocketmq.common.protocol.body.ClusterInfo.getBrokerAddrTable方法的典型用法代码示例。如果您正苦于以下问题:Java ClusterInfo.getBrokerAddrTable方法的具体用法?Java ClusterInfo.getBrokerAddrTable怎么用?Java ClusterInfo.getBrokerAddrTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.rocketmq.common.protocol.body.ClusterInfo
的用法示例。
在下文中一共展示了ClusterInfo.getBrokerAddrTable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExamineBrokerClusterInfo
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入方法依赖的package包/类
@Test
public void testExamineBrokerClusterInfo() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
HashMap<String, BrokerData> brokerList = clusterInfo.getBrokerAddrTable();
assertThat(brokerList.get("default-broker").getBrokerName()).isEqualTo("default-broker");
assertThat(brokerList.containsKey("broker-test")).isTrue();
HashMap<String, Set<String>> clusterMap = new HashMap<>();
Set<String> brokers = new HashSet<>();
brokers.add("default-broker");
brokers.add("broker-test");
clusterMap.put("default-cluster", brokers);
ClusterInfo cInfo = mock(ClusterInfo.class);
when(cInfo.getClusterAddrTable()).thenReturn(clusterMap);
HashMap<String, Set<String>> clusterAddress = cInfo.getClusterAddrTable();
assertThat(clusterAddress.containsKey("default-cluster")).isTrue();
assertThat(clusterAddress.get("default-cluster").size()).isEqualTo(2);
}
示例2: isBrokerExist
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入方法依赖的package包/类
public static boolean isBrokerExist(String ns, String ip) {
ClusterInfo clusterInfo = getCluster(ns);
if (clusterInfo == null) {
return false;
} else {
HashMap<String, BrokerData> brokers = clusterInfo.getBrokerAddrTable();
for (String brokerName : brokers.keySet()) {
HashMap<Long, String> brokerIps = brokers.get(brokerName).getBrokerAddrs();
for (long brokerId : brokerIps.keySet()) {
if (brokerIps.get(brokerId).contains(ip))
return true;
}
}
}
return false;
}
示例3: fetchBrokerNameByAddr
import org.apache.rocketmq.common.protocol.body.ClusterInfo; //导入方法依赖的package包/类
public static String fetchBrokerNameByAddr(final MQAdminExt adminExt, final String addr) throws Exception {
ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo();
HashMap<String/* brokerName */, BrokerData> 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.");
}