mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
增加Apache Pulsar MQ支持 (#3791)
* done pulsarmq * del pulsar consumer * pulsar partition * done pulsar consumer&connector * update pulsar-client version to 2.8.1 Co-authored-by: agapple <jianghang115@gmail.com>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package com.alibaba.otter.canal.common.utils;
|
||||
|
||||
|
||||
public class MQUtil {
|
||||
/**
|
||||
* topic是否是正则表达式
|
||||
*
|
||||
* @param topic
|
||||
* @return true是正则表达式
|
||||
*/
|
||||
public static boolean isPatternTopic(String topic) {
|
||||
return !topic.matches("^[0-9a-z:/-]+$");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查topic有效性
|
||||
*
|
||||
* @param topic
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkTopic(String topic) {
|
||||
return topic.matches("^[0-9a-z:/.*-]+$");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查tag有效性
|
||||
*
|
||||
* @param tag
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkTag(String tag) {
|
||||
return tag.matches("^[0-9a-zA-Z.*]+$");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断tag是否是正则
|
||||
*
|
||||
* @param tag
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPatternTag(String tag) {
|
||||
return !tag.matches("^[0-9a-zA-Z]+$");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查topic有效性
|
||||
*
|
||||
* @param topics
|
||||
*/
|
||||
public static void checkTopicWithErr(String... topics) {
|
||||
if (null == topics || 0 == topics.length) {
|
||||
throw new NullPointerException("topic cannot null");
|
||||
}
|
||||
|
||||
if (1 == topics.length) {
|
||||
boolean ok = checkTopic(topics[0]);
|
||||
if (ok) {
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("topic invalid: " + topics[0]);
|
||||
}
|
||||
|
||||
for (String t : topics) {
|
||||
if (!checkTopic(t)) {
|
||||
throw new IllegalArgumentException("topic invalid: " + t);
|
||||
}
|
||||
if (isPatternTopic(t)) {
|
||||
throw new RuntimeException("pattern topic cannot multi: " + t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查tag有效性
|
||||
*
|
||||
* @param tags
|
||||
*/
|
||||
public static void checkTagWithErr(String... tags) {
|
||||
// 空表示不使用tag
|
||||
if (null == tags || 0 == tags.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if (1 == tags.length && (null == tags[0] || 0 == tags[0].trim().length())) {
|
||||
// throw new NullPointerException("tag cannot null");
|
||||
// }
|
||||
|
||||
for (String t : tags) {
|
||||
if (!checkTag(t)) {
|
||||
throw new IllegalArgumentException("tag invalid: " + t);
|
||||
}
|
||||
if (isPatternTag(t)) {
|
||||
throw new RuntimeException("pattern tag cannot multi: " + t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user