use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.
the class DefaultMQAdminExtImpl method consumed.
public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
ConsumeStats cstats = this.examineConsumeStats(group);
ClusterInfo ci = this.examineBrokerClusterInfo();
Iterator<Entry<MessageQueue, OffsetWrapper>> it = cstats.getOffsetTable().entrySet().iterator();
while (it.hasNext()) {
Entry<MessageQueue, OffsetWrapper> next = it.next();
MessageQueue mq = next.getKey();
if (mq.getTopic().equals(msg.getTopic()) && mq.getQueueId() == msg.getQueueId()) {
BrokerData brokerData = ci.getBrokerAddrTable().get(mq.getBrokerName());
if (brokerData != null) {
String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
if (addr.equals(RemotingUtil.socketAddress2String(msg.getStoreHost()))) {
if (next.getValue().getConsumerOffset() > msg.getQueueOffset()) {
return true;
}
}
}
}
}
return false;
}
use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.
the class DefaultMQAdminExtImpl method examineConsumerConnectionInfo.
@Override
public ConsumerConnection examineConsumerConnectionInfo(String consumerGroup) throws InterruptedException, MQBrokerException, RemotingException, MQClientException {
ConsumerConnection result = new ConsumerConnection();
String topic = MixAll.getRetryTopic(consumerGroup);
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().getConsumerConnectionList(addr, consumerGroup, timeoutMillis);
}
}
if (result.getConnectionSet().isEmpty()) {
log.warn("the consumer group not online. brokerAddr={}, group={}", addr, consumerGroup);
throw new MQClientException(ResponseCode.CONSUMER_NOT_ONLINE, "Not found the consumer group connection");
}
return result;
}
use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.
the class DefaultMQAdminExtImpl method resetOffsetByTimestampOld.
@Override
public List<RollbackStats> resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, boolean force) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
List<RollbackStats> rollbackStatsList = new ArrayList<RollbackStats>();
Map<String, Integer> topicRouteMap = new HashMap<String, Integer>();
for (BrokerData bd : topicRouteData.getBrokerDatas()) {
for (QueueData queueData : topicRouteData.getQueueDatas()) {
topicRouteMap.put(bd.selectBrokerAddr(), queueData.getReadQueueNums());
}
}
for (BrokerData bd : topicRouteData.getBrokerDatas()) {
String addr = bd.selectBrokerAddr();
if (addr != null) {
ConsumeStats consumeStats = this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, timeoutMillis);
boolean hasConsumed = false;
for (Map.Entry<MessageQueue, OffsetWrapper> entry : consumeStats.getOffsetTable().entrySet()) {
MessageQueue queue = entry.getKey();
OffsetWrapper offsetWrapper = entry.getValue();
if (topic.equals(queue.getTopic())) {
hasConsumed = true;
RollbackStats rollbackStats = resetOffsetConsumeOffset(addr, consumerGroup, queue, offsetWrapper, timestamp, force);
rollbackStatsList.add(rollbackStats);
}
}
if (!hasConsumed) {
HashMap<MessageQueue, TopicOffset> topicStatus = this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis).getOffsetTable();
for (int i = 0; i < topicRouteMap.get(addr); i++) {
MessageQueue queue = new MessageQueue(topic, bd.getBrokerName(), i);
OffsetWrapper offsetWrapper = new OffsetWrapper();
offsetWrapper.setBrokerOffset(topicStatus.get(queue).getMaxOffset());
offsetWrapper.setConsumerOffset(topicStatus.get(queue).getMinOffset());
RollbackStats rollbackStats = resetOffsetConsumeOffset(addr, consumerGroup, queue, offsetWrapper, timestamp, force);
rollbackStatsList.add(rollbackStats);
}
}
}
}
return rollbackStatsList;
}
use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq-externals by apache.
the class HudiSinkConnector method buildRoute.
public void buildRoute() {
String srcCluster = this.sinkConnectConfig.getSrcCluster();
try {
for (String topic : this.sinkConnectConfig.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++) {
MessageQueue taskTopicInfo = new MessageQueue(topic, qd.getBrokerName(), i);
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.BrokerData 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;
}
Aggregations