|
@@ -103,6 +103,38 @@ public class MQMessageUtils {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ private static Map<String, List<TopicPartitionData>> topicPartitionDatas = MigrateMap.makeComputingMap(CacheBuilder.newBuilder()
|
|
|
|
+ .softValues(),
|
|
|
|
+ new Function<String, List<TopicPartitionData>>() {
|
|
|
|
+
|
|
|
|
+ public List<TopicPartitionData> apply(String tPConfigs) {
|
|
|
|
+ List<TopicPartitionData> datas = Lists.newArrayList();
|
|
|
|
+ String[] tPArray = StringUtils.split(StringUtils.replace(tPConfigs,
|
|
|
|
+ ",",
|
|
|
|
+ ";"),
|
|
|
|
+ ";");
|
|
|
|
+ for (String tPConfig : tPArray) {
|
|
|
|
+ TopicPartitionData data = new TopicPartitionData();
|
|
|
|
+ int i = tPConfig.lastIndexOf(":");
|
|
|
|
+ if (i > 0) {
|
|
|
|
+ String tStr = tPConfig.substring(0, i);
|
|
|
|
+ String pStr = tPConfig.substring(i + 1);
|
|
|
|
+ if (!isWildCard(tStr)) {
|
|
|
|
+ data.simpleName = tStr;
|
|
|
|
+ } else {
|
|
|
|
+ data.regexFilter = new AviaterRegexFilter(tStr);
|
|
|
|
+ }
|
|
|
|
+ if (!StringUtils.isEmpty(pStr) && StringUtils.isNumeric(pStr)) {
|
|
|
|
+ data.partitionNum = Integer.valueOf(pStr);
|
|
|
|
+ }
|
|
|
|
+ datas.add(data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return datas;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 按 schema 或者 schema+table 将 message 分配到对应topic
|
|
* 按 schema 或者 schema+table 将 message 分配到对应topic
|
|
*
|
|
*
|
|
@@ -619,6 +651,24 @@ public class MQMessageUtils {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static Integer parseDynamicTopicPartition(String name, String tPConfigs) {
|
|
|
|
+ if (!StringUtils.isEmpty(tPConfigs)) {
|
|
|
|
+ List<TopicPartitionData> datas = topicPartitionDatas.get(tPConfigs);
|
|
|
|
+ for (TopicPartitionData data : datas) {
|
|
|
|
+ if (data.simpleName != null) {
|
|
|
|
+ if (data.simpleName.equalsIgnoreCase(name)) {
|
|
|
|
+ return data.partitionNum;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (data.regexFilter.filter(name)) {
|
|
|
|
+ return data.partitionNum;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
private static boolean isWildCard(String value) {
|
|
private static boolean isWildCard(String value) {
|
|
// not contaiins '.' ?
|
|
// not contaiins '.' ?
|
|
return StringUtils.containsAny(value, new char[] { '*', '?', '+', '|', '(', ')', '{', '}', '[', ']', '\\', '$',
|
|
return StringUtils.containsAny(value, new char[] { '*', '?', '+', '|', '(', ')', '{', '}', '[', ']', '\\', '$',
|
|
@@ -656,6 +706,13 @@ public class MQMessageUtils {
|
|
public AviaterRegexFilter tableRegexFilter;
|
|
public AviaterRegexFilter tableRegexFilter;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static class TopicPartitionData {
|
|
|
|
+
|
|
|
|
+ public String simpleName;
|
|
|
|
+ public AviaterRegexFilter regexFilter;
|
|
|
|
+ public Integer partitionNum;
|
|
|
|
+ }
|
|
|
|
+
|
|
public static class EntryRowData {
|
|
public static class EntryRowData {
|
|
|
|
|
|
public Entry entry;
|
|
public Entry entry;
|