use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq by apache.
the class DefaultMQAdminExtImpl method resetOffsetByTimestamp.
public Map<MessageQueue, Long> resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, boolean isC) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
Map<MessageQueue, Long> allOffsetTable = new HashMap<MessageQueue, Long>();
if (brokerDatas != null) {
for (BrokerData brokerData : brokerDatas) {
String addr = brokerData.selectBrokerAddr();
if (addr != null) {
Map<MessageQueue, Long> offsetTable = this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce, timeoutMillis, isC);
if (offsetTable != null) {
allOffsetTable.putAll(offsetTable);
}
}
}
}
return allOffsetTable;
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq by apache.
the class DefaultMQAdminExtImpl method examineConsumeStats.
@Override
public ConsumeStats examineConsumeStats(String consumerGroup, String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
String retryTopic = MixAll.getRetryTopic(consumerGroup);
TopicRouteData topicRouteData = this.examineTopicRouteInfo(retryTopic);
ConsumeStats result = new ConsumeStats();
for (BrokerData bd : topicRouteData.getBrokerDatas()) {
String addr = bd.selectBrokerAddr();
if (addr != null) {
ConsumeStats consumeStats = this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, topic, timeoutMillis * 3);
result.getOffsetTable().putAll(consumeStats.getOffsetTable());
double value = result.getConsumeTps() + consumeStats.getConsumeTps();
result.setConsumeTps(value);
}
}
if (result.getOffsetTable().isEmpty()) {
throw new MQClientException(ResponseCode.CONSUMER_NOT_ONLINE, "Not found the consumer group consume stats, because return offset table is empty, maybe the consumer not consume any message");
}
return result;
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq by apache.
the class DefaultMQAdminExtImpl method examineTopicStats.
@Override
public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
TopicStatsTable topicStatsTable = new TopicStatsTable();
for (BrokerData bd : topicRouteData.getBrokerDatas()) {
String addr = bd.selectBrokerAddr();
if (addr != null) {
TopicStatsTable tst = this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis);
topicStatsTable.getOffsetTable().putAll(tst.getOffsetTable());
}
}
if (topicStatsTable.getOffsetTable().isEmpty()) {
throw new MQClientException("Not found the topic stats info", null);
}
return topicStatsTable;
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.
the class OffsetSyncStore method sync.
private boolean sync(Duration pullTimeout) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
TopicRouteData route = adminExt.examineTopicRouteInfo(taskConfig.getOffsetSyncTopic());
String brokerName = route.getQueueDatas().get(0).getBrokerName();
MessageQueue mq = new MessageQueue(taskConfig.getOffsetSyncTopic(), brokerName, 0);
PullResult pr = consumer.pull(mq, "", lastOffset, 0, pullTimeout.getNano() / Duration.ofMillis(1).getNano());
if (pr.getPullStatus() != PullStatus.FOUND) {
return false;
}
handle(pr);
return true;
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.
the class RmqSourceReplicator method buildRoute.
public void buildRoute() {
List<Pattern> patterns = new ArrayList<Pattern>();
String srcCluster = this.replicatorConfig.getSrcCluster();
try {
Set<String> targetTopicSet = fetchTargetTopics();
for (String topic : this.replicatorConfig.getWhiteList()) {
Pattern pattern = Pattern.compile(topic);
patterns.add(pattern);
}
TopicList topics = srcMQAdminExt.fetchAllTopicList();
for (String topic : topics.getTopicList()) {
if (topic.equals(ConfigDefine.CONN_STORE_TOPIC)) {
continue;
}
if (!syncRETRY && topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
continue;
}
if (!syncDLQ && topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
continue;
}
for (Pattern pattern : patterns) {
Matcher matcher = pattern.matcher(topic);
if (matcher.matches()) {
String targetTopic = generateTargetTopic(topic);
if (!targetTopicSet.contains(targetTopic)) {
ensureTargetTopic(topic, targetTopic);
}
// 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, targetTopic);
topicRouteMap.get(topic).add(taskTopicInfo);
}
}
}
}
}
}
} catch (Exception e) {
log.error("Fetch topic list error.", e);
}
}
Aggregations