use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.
the class RmqSourceReplicator method ensureTargetTopic.
/**
* ensure target topic eixst. if target topic does not exist, ensureTopic will create target topic on target
* cluster, with same TopicConfig but using target topic name. any exception will be caught and then throw
* IllegalStateException.
*
* @param srcTopic
* @param targetTopic
* @throws RemotingException
* @throws MQClientException
* @throws InterruptedException
*/
public void ensureTargetTopic(String srcTopic, String targetTopic) throws RemotingException, MQClientException, InterruptedException {
String srcCluster = this.replicatorConfig.getSrcCluster();
String targetCluster = this.replicatorConfig.getTargetCluster();
List<BrokerData> brokerList = Utils.examineBrokerData(this.srcMQAdminExt, srcTopic, srcCluster);
if (brokerList.size() == 0) {
throw new IllegalStateException(String.format("no broker found for srcTopic: %s srcCluster: %s", srcTopic, srcCluster));
}
final TopicRouteData topicRouteData = this.srcMQAdminExt.examineTopicRouteInfo(srcTopic);
final TopicConfig topicConfig = new TopicConfig();
final List<QueueData> queueDatas = topicRouteData.getQueueDatas();
QueueData queueData = queueDatas.get(0);
topicConfig.setPerm(queueData.getPerm());
topicConfig.setReadQueueNums(queueData.getReadQueueNums());
topicConfig.setWriteQueueNums(queueData.getWriteQueueNums());
topicConfig.setTopicSysFlag(queueData.getTopicSynFlag());
topicConfig.setTopicName(targetTopic);
Utils.createTopic(this.targetMQAdminExt, topicConfig, targetCluster);
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.
the class Utils method examineBrokerData.
public static List<BrokerData> examineBrokerData(DefaultMQAdminExt defaultMQAdminExt, String topic, String cluster) throws RemotingException, MQClientException, InterruptedException {
List<BrokerData> brokerList = new ArrayList<>();
TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
if (topicRouteData.getBrokerDatas() != null) {
for (BrokerData broker : topicRouteData.getBrokerDatas()) {
if (StringUtils.equals(broker.getCluster(), cluster)) {
brokerList.add(broker);
}
}
}
return brokerList;
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.
the class CassandraSinkConnector method buildRoute.
public void buildRoute() {
String srcCluster = ((SinkDbConnectorConfig) this.dbConnectorConfig).getSrcCluster();
try {
for (String topic : ((SinkDbConnectorConfig) this.dbConnectorConfig).getWhiteList()) {
// different from BrokerData with cluster field, which can ensure the brokerData is from expected cluster.
// QueueData use brokerName as unique info on cluster of rocketmq. so when we want to get QueueData of
// expected cluster, we should get brokerNames of expected cluster, and then filter queueDatas.
List<BrokerData> brokerList = Utils.examineBrokerData(this.srcMQAdminExt, topic, srcCluster);
Set<String> brokerNameSet = new HashSet<String>();
for (BrokerData b : brokerList) {
brokerNameSet.add(b.getBrokerName());
}
TopicRouteData topicRouteData = srcMQAdminExt.examineTopicRouteInfo(topic);
if (!topicRouteMap.containsKey(topic)) {
topicRouteMap.put(topic, new HashSet<>(16));
}
for (QueueData qd : topicRouteData.getQueueDatas()) {
if (brokerNameSet.contains(qd.getBrokerName())) {
for (int i = 0; i < qd.getReadQueueNums(); i++) {
TaskTopicInfo taskTopicInfo = new TaskTopicInfo(topic, qd.getBrokerName(), i, null);
topicRouteMap.get(topic).add(taskTopicInfo);
}
}
}
}
} catch (Exception e) {
log.error("Fetch topic list error.", e);
} finally {
// srcMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.
the class Utils method examineBrokerData.
public static List<BrokerData> examineBrokerData(DefaultMQAdminExt defaultMQAdminExt, String topic, String cluster) throws RemotingException, MQClientException, InterruptedException {
List<BrokerData> brokerList = new ArrayList<>();
TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
if (topicRouteData.getBrokerDatas() != null) {
for (BrokerData broker : topicRouteData.getBrokerDatas()) {
if (StringUtils.equals(broker.getCluster(), cluster)) {
brokerList.add(broker);
}
}
}
return brokerList;
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class MQClientInstance method isBrokerInNameServer.
private boolean isBrokerInNameServer(final String brokerAddr) {
Iterator<Entry<String, TopicRouteData>> it = this.topicRouteTable.entrySet().iterator();
while (it.hasNext()) {
Entry<String, TopicRouteData> itNext = it.next();
List<BrokerData> brokerDatas = itNext.getValue().getBrokerDatas();
for (BrokerData bd : brokerDatas) {
boolean contain = bd.getBrokerAddrs().containsValue(brokerAddr);
if (contain)
return true;
}
}
return false;
}
Aggregations