use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq by apache.
the class ExportMetadataCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
defaultMQAdminExt.start();
String filePath = !commandLine.hasOption('f') ? DEFAULT_FILE_PATH : commandLine.getOptionValue('f').trim();
boolean specialTopic = commandLine.hasOption('s');
if (commandLine.hasOption('b')) {
final String brokerAddr = commandLine.getOptionValue('b').trim();
if (commandLine.hasOption('t')) {
filePath = filePath + "/topic.json";
TopicConfigSerializeWrapper topicConfigSerializeWrapper = defaultMQAdminExt.getUserTopicConfig(brokerAddr, specialTopic, 10000L);
MixAll.string2FileNotSafe(JSON.toJSONString(topicConfigSerializeWrapper, true), filePath);
System.out.printf("export %s success", filePath);
} else if (commandLine.hasOption('g')) {
filePath = filePath + "/subscriptionGroup.json";
SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt.getUserSubscriptionGroup(brokerAddr, 10000L);
MixAll.string2FileNotSafe(JSON.toJSONString(subscriptionGroupWrapper, true), filePath);
System.out.printf("export %s success", filePath);
}
} else if (commandLine.hasOption('c')) {
String clusterName = commandLine.getOptionValue('c').trim();
Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName);
Map<String, TopicConfig> topicConfigMap = new HashMap<>();
Map<String, SubscriptionGroupConfig> subGroupConfigMap = new HashMap<>();
Map<String, Object> result = new HashMap<>();
for (String addr : masterSet) {
TopicConfigSerializeWrapper topicConfigSerializeWrapper = defaultMQAdminExt.getUserTopicConfig(addr, specialTopic, 10000L);
SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt.getUserSubscriptionGroup(addr, 10000);
for (Map.Entry<String, TopicConfig> entry : topicConfigSerializeWrapper.getTopicConfigTable().entrySet()) {
TopicConfig topicConfig = topicConfigMap.get(entry.getKey());
if (null != topicConfig) {
entry.getValue().setWriteQueueNums(topicConfig.getWriteQueueNums() + entry.getValue().getWriteQueueNums());
entry.getValue().setReadQueueNums(topicConfig.getReadQueueNums() + entry.getValue().getReadQueueNums());
}
topicConfigMap.put(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, SubscriptionGroupConfig> entry : subscriptionGroupWrapper.getSubscriptionGroupTable().entrySet()) {
SubscriptionGroupConfig subscriptionGroupConfig = subGroupConfigMap.get(entry.getKey());
if (null != subscriptionGroupConfig) {
entry.getValue().setRetryQueueNums(subscriptionGroupConfig.getRetryQueueNums() + entry.getValue().getRetryQueueNums());
}
subGroupConfigMap.put(entry.getKey(), entry.getValue());
}
}
String exportPath;
if (commandLine.hasOption('t')) {
result.put("topicConfigTable", topicConfigMap);
exportPath = filePath + "/topic.json";
} else if (commandLine.hasOption('g')) {
result.put("subscriptionGroupTable", subGroupConfigMap);
exportPath = filePath + "/subscriptionGroup.json";
} else {
result.put("topicConfigTable", topicConfigMap);
result.put("subscriptionGroupTable", subGroupConfigMap);
exportPath = filePath + "/metadata.json";
}
result.put("exportTime", System.currentTimeMillis());
MixAll.string2FileNotSafe(JSON.toJSONString(result, true), exportPath);
System.out.printf("export %s success%n", exportPath);
} else {
ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq by apache.
the class DefaultMQAdminExtImpl method getUserSubscriptionGroup.
@Override
public SubscriptionGroupWrapper getUserSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
SubscriptionGroupWrapper subscriptionGroupWrapper = this.mqClientInstance.getMQClientAPIImpl().getAllSubscriptionGroup(brokerAddr, timeoutMillis);
Iterator<Entry<String, SubscriptionGroupConfig>> iterator = subscriptionGroupWrapper.getSubscriptionGroupTable().entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, SubscriptionGroupConfig> configEntry = iterator.next();
if (MixAll.isSysConsumerGroup(configEntry.getKey()) || SYSTEM_GROUP_SET.contains(configEntry.getKey())) {
iterator.remove();
}
}
return subscriptionGroupWrapper;
}
use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq by apache.
the class SlaveSynchronize method syncSubscriptionGroupConfig.
private void syncSubscriptionGroupConfig() {
String masterAddrBak = this.masterAddr;
if (masterAddrBak != null && !masterAddrBak.equals(brokerController.getBrokerAddr())) {
try {
SubscriptionGroupWrapper subscriptionWrapper = this.brokerController.getBrokerOuterAPI().getAllSubscriptionGroupConfig(masterAddrBak);
if (!this.brokerController.getSubscriptionGroupManager().getDataVersion().equals(subscriptionWrapper.getDataVersion())) {
SubscriptionGroupManager subscriptionGroupManager = this.brokerController.getSubscriptionGroupManager();
subscriptionGroupManager.getDataVersion().assignNewOne(subscriptionWrapper.getDataVersion());
subscriptionGroupManager.getSubscriptionGroupTable().clear();
subscriptionGroupManager.getSubscriptionGroupTable().putAll(subscriptionWrapper.getSubscriptionGroupTable());
subscriptionGroupManager.persist();
log.info("Update slave Subscription Group from master, {}", masterAddrBak);
}
} catch (Exception e) {
log.error("SyncSubscriptionGroup Exception, {}", masterAddrBak, e);
}
}
}
use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq by apache.
the class DefaultMQAdminExtTest method testGetAllSubscriptionGroup.
@Test
public void testGetAllSubscriptionGroup() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt.getAllSubscriptionGroup("127.0.0.1:10911", 10000);
assertThat(subscriptionGroupWrapper.getSubscriptionGroupTable().get("Consumer-group-one").getBrokerId()).isEqualTo(1234);
assertThat(subscriptionGroupWrapper.getSubscriptionGroupTable().get("Consumer-group-one").getGroupName()).isEqualTo("Consumer-group-one");
assertThat(subscriptionGroupWrapper.getSubscriptionGroupTable().get("Consumer-group-one").isConsumeBroadcastEnable()).isTrue();
}
use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq-connect by apache.
the class ConnectUtil method fetchAllConsumerGroupList.
public static Set<String> fetchAllConsumerGroupList(ConnectConfig connectConfig) {
Set<String> consumerGroupSet = Sets.newHashSet();
DefaultMQAdminExt defaultMQAdminExt = null;
try {
defaultMQAdminExt = startMQAdminTool(connectConfig);
ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
for (BrokerData brokerData : clusterInfo.getBrokerAddrTable().values()) {
SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt.getAllSubscriptionGroup(brokerData.selectBrokerAddr(), 3000L);
consumerGroupSet.addAll(subscriptionGroupWrapper.getSubscriptionGroupTable().keySet());
}
} catch (Exception e) {
throw new RuntimeException("fetch all topic failed", e);
} finally {
if (defaultMQAdminExt != null) {
defaultMQAdminExt.shutdown();
}
}
return consumerGroupSet;
}
Aggregations