You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/10/15 06:23:48 UTC

[incubator-eventmesh] branch protocol-amqp updated: exchange utils and name check util

This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch protocol-amqp
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/protocol-amqp by this push:
     new 1435a9fe exchange utils and name check util
     new 77cbcc8e Merge pull request #1598 from wangshaojie4039/protocol-amqp
1435a9fe is described below

commit 1435a9fe59c56a6b24edcfc56a7dad72c2da6084
Author: wangshaojie <wa...@cmss.chinamobile.com>
AuthorDate: Sat Oct 15 14:21:34 2022 +0800

    exchange utils and name check util
---
 .../core/protocol/amqp/util/ExchangeUtil.java      | 70 ++++++++++++++++++++++
 .../runtime/core/protocol/amqp/util/NameUtils.java | 37 ++++++++++++
 2 files changed, 107 insertions(+)

diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/util/ExchangeUtil.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/util/ExchangeUtil.java
new file mode 100644
index 00000000..f02fbf0f
--- /dev/null
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/util/ExchangeUtil.java
@@ -0,0 +1,70 @@
+package org.apache.eventmesh.runtime.core.protocol.amqp.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.eventmesh.runtime.core.protocol.amqp.exchange.ExchangeDefaults;
+import org.apache.eventmesh.runtime.core.protocol.amqp.exchange.ExchangeType;
+import org.apache.eventmesh.runtime.core.protocol.amqp.metadata.model.ExchangeInfo;
+
+public class ExchangeUtil {
+
+    public static boolean isBuildInExchange(final String exchangeName) {
+        if (exchangeName.equals(ExchangeDefaults.DIRECT_EXCHANGE_NAME)
+            || (exchangeName.equals(ExchangeDefaults.FANOUT_EXCHANGE_NAME))
+            || (exchangeName.equals(ExchangeDefaults.TOPIC_EXCHANGE_NAME))
+            || (exchangeName.equals(ExchangeDefaults.HEADERS_EXCHANGE_NAME))) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+
+
+    public static boolean isDefaultExchange(final String exchangeName) {
+        return StringUtils.isBlank(exchangeName)
+            || (ExchangeDefaults.DEFAULT_EXCHANGE_NAME_DURABLE.equals(exchangeName))
+            || (ExchangeDefaults.DEFAULT_EXCHANGE_NAME.equals(exchangeName));
+    }
+
+    public static ExchangeType getBuildInExchangeType(String exchangeName) {
+        if (null == exchangeName) {
+            exchangeName = "";
+        }
+        switch (exchangeName) {
+            case "":
+            case ExchangeDefaults.DIRECT_EXCHANGE_NAME:
+                return ExchangeType.Direct;
+            case ExchangeDefaults.FANOUT_EXCHANGE_NAME:
+                return ExchangeType.Fanout;
+            case ExchangeDefaults.TOPIC_EXCHANGE_NAME:
+                return ExchangeType.Topic;
+            default:
+                return null;
+        }
+    }
+
+    public static ExchangeInfo defaultExchange() {
+        return new ExchangeInfo(ExchangeDefaults.DEFAULT_EXCHANGE_NAME_DURABLE, true, false,
+            ExchangeType.value(ExchangeDefaults.DIRECT_EXCHANGE_CLASS));
+    }
+
+    public static ExchangeInfo defaultDirectExchange() {
+        return new ExchangeInfo(ExchangeDefaults.DIRECT_EXCHANGE_NAME, true, false,
+            ExchangeType.value(ExchangeDefaults.DIRECT_EXCHANGE_CLASS));
+    }
+
+    public static ExchangeInfo defaultFanoutExchange() {
+        return new ExchangeInfo(ExchangeDefaults.FANOUT_EXCHANGE_NAME, true, false,
+            ExchangeType.value(ExchangeDefaults.FANOUT_EXCHANGE_CLASS));
+    }
+
+    public static ExchangeInfo defaultTopicExchange() {
+        return new ExchangeInfo(ExchangeDefaults.TOPIC_EXCHANGE_NAME, true, false,
+            ExchangeType.value(ExchangeDefaults.TOPIC_EXCHANGE_CLASS));
+    }
+
+    public static ExchangeInfo defaultHeaderExchange() {
+        return new ExchangeInfo(ExchangeDefaults.HEADERS_EXCHANGE_NAME, true, false,
+            ExchangeType.value(ExchangeDefaults.HEADERS_EXCHANGE_CLASS));
+    }
+}
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/util/NameUtils.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/util/NameUtils.java
new file mode 100644
index 00000000..00e33ae0
--- /dev/null
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/util/NameUtils.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.runtime.core.protocol.amqp.util;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Name Util.
+ */
+public class NameUtils {
+    public static final Pattern NAMED_PATTERN = Pattern.compile("^[-._@\\w]{3,256}$");
+
+    //可包含字母、数字、短划线(-)、下划线(_)、点(.)和 @符号
+    //长度限制3-256个字符之间
+    public static void checkName(String name) {
+        Matcher m = NAMED_PATTERN.matcher(name);
+        if (!m.matches()) {
+            throw new IllegalArgumentException("Invalid named : " + name);
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org