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:02:38 UTC

[incubator-eventmesh] branch protocol-amqp updated: realization amqp exchange manager

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 e43cd8dc realization amqp exchange manager
     new 06759a73 Merge pull request #1591 from wangshaojie4039/protocol-amqp
e43cd8dc is described below

commit e43cd8dc4189dbc76c40c05be20411f63fcfadad
Author: wangshaojie <wa...@cmss.chinamobile.com>
AuthorDate: Sat Oct 15 13:58:51 2022 +0800

    realization amqp exchange manager
---
 .../amqp/metadata/manager/ExchangeManager.java     |  55 +++++++++
 .../manager/ExchangeManagerMemoryImpl.java         | 135 +++++++++++++++++++++
 2 files changed, 190 insertions(+)

diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/ExchangeManager.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/ExchangeManager.java
new file mode 100644
index 00000000..2774f4b5
--- /dev/null
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/ExchangeManager.java
@@ -0,0 +1,55 @@
+/*
+ * 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.metadata.manager;
+
+import org.apache.eventmesh.runtime.core.protocol.amqp.exception.AmqpNotFoundException;
+import org.apache.eventmesh.runtime.core.protocol.amqp.metadata.model.BindingInfo;
+import org.apache.eventmesh.runtime.core.protocol.amqp.metadata.model.ExchangeInfo;
+
+import java.util.Set;
+
+public interface ExchangeManager {
+
+    void createExchange(String virtualHostName, final String exchangeName, ExchangeInfo meta) throws AmqpNotFoundException;
+
+    ExchangeInfo getExchange(String virtualHostName, final String exchangeName);
+
+
+    void deleteExchange(String virtualHostName, final String exchangeName);
+
+
+    void exchangeBind(final String virtualHostName, String exchange, String queue,
+                      BindingInfo bindingInfo) throws AmqpNotFoundException;
+
+    void exchangeUnBind(final String virtualHostName, String exchange,
+                        String queue, String bindingKey) throws AmqpNotFoundException;
+
+
+    void exchangeUnBind(String virtualHostName, final String exchangeName, String queue) throws AmqpNotFoundException;
+
+    void exchangeUnBindAll(String virtualHostName, final String exchangeName) throws AmqpNotFoundException;
+
+    Set<BindingInfo> getBindings(String virtualHostName, String exchangeName) throws Exception;
+
+    boolean isQueueBindingExist(String virtualHostName, String exchangeName, String queue) throws AmqpNotFoundException;
+
+    boolean checkExist(String virtualHostName, String exchangeName);
+
+    Set<String> getExchangeList(String virtualHostName) throws Exception;
+
+}
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/ExchangeManagerMemoryImpl.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/ExchangeManagerMemoryImpl.java
new file mode 100644
index 00000000..84506d2b
--- /dev/null
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/ExchangeManagerMemoryImpl.java
@@ -0,0 +1,135 @@
+/*
+ * 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.metadata.manager;
+
+import org.apache.eventmesh.runtime.core.protocol.amqp.exception.AmqpNotFoundException;
+import org.apache.eventmesh.runtime.core.protocol.amqp.metadata.model.BindingInfo;
+import org.apache.eventmesh.runtime.core.protocol.amqp.metadata.model.ExchangeInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ExchangeManagerMemoryImpl implements ExchangeManager {
+
+    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
+
+    private ConcurrentHashMap<String, ConcurrentHashMap<String, ExchangeInfo>> exchangeMapping = new ConcurrentHashMap<>();
+
+    @Override
+    public void createExchange(String virtualHostName, String exchangeName, ExchangeInfo meta) throws AmqpNotFoundException {
+        ConcurrentHashMap<String, ExchangeInfo> infoMap = exchangeMapping.computeIfAbsent(virtualHostName, m -> new ConcurrentHashMap<>());
+        if (infoMap == null) {
+            log.error("virtualHost not found {}", virtualHostName);
+            throw new AmqpNotFoundException("vhost not found");
+        }
+        if (!infoMap.containsKey(exchangeName)) {
+            infoMap.put(exchangeName, meta);
+        }
+    }
+
+
+    @Override
+    public ExchangeInfo getExchange(String virtualHostName, String exchangeName) {
+        ConcurrentHashMap<String, ExchangeInfo> map = exchangeMapping.get(virtualHostName);
+        if (map != null) {
+            return map.get(exchangeName);
+        }
+        return null;
+    }
+
+    @Override
+    public void deleteExchange(String virtualHostName, String exchangeName) {
+        ConcurrentHashMap<String, ExchangeInfo> map = exchangeMapping.get(virtualHostName);
+        if (map != null) {
+            map.remove(exchangeName);
+        }
+
+    }
+
+    @Override
+    public void exchangeBind(String virtualHostName, String exchange, String queue, BindingInfo bindingInfo) throws AmqpNotFoundException {
+        ExchangeInfo exchangeInfo = getExchange(virtualHostName, exchange);
+        if (exchangeInfo == null) {
+            throw new AmqpNotFoundException("exchange not found");
+        }
+        exchangeInfo.addBinding(queue, bindingInfo);
+    }
+
+    @Override
+    public void exchangeUnBind(String virtualHostName, String exchange, String queue, String bindingKey) throws AmqpNotFoundException {
+        ExchangeInfo exchangeInfo = getExchange(virtualHostName, exchange);
+        if (exchangeInfo == null) {
+            throw new AmqpNotFoundException("exchange not found");
+        }
+        exchangeInfo.removeBinding(queue, bindingKey);
+    }
+
+    @Override
+    public void exchangeUnBind(String virtualHostName, String exchangeName, String queue) throws AmqpNotFoundException {
+        ExchangeInfo exchangeInfo = getExchange(virtualHostName, exchangeName);
+        if (exchangeInfo == null) {
+            throw new AmqpNotFoundException("exchange not found");
+        }
+        exchangeInfo.removeBinding(queue);
+    }
+
+    @Override
+    public void exchangeUnBindAll(String virtualHostName, String exchangeName) throws AmqpNotFoundException {
+        ExchangeInfo exchangeInfo = getExchange(virtualHostName, exchangeName);
+        if (exchangeInfo == null) {
+            throw new AmqpNotFoundException("exchange not found");
+        }
+        exchangeInfo.removeAll();
+    }
+
+    @Override
+    public Set<BindingInfo> getBindings(String virtualHostName, String exchangeName) throws Exception {
+        ExchangeInfo exchangeInfo = getExchange(virtualHostName, exchangeName);
+        if (exchangeInfo == null) {
+            throw new AmqpNotFoundException("exchange not found");
+        }
+        return exchangeInfo.getBindings();
+    }
+
+    @Override
+    public boolean isQueueBindingExist(String virtualHostName, String exchangeName, String queue) throws AmqpNotFoundException {
+        ExchangeInfo exchangeInfo = getExchange(virtualHostName, exchangeName);
+        if (exchangeInfo == null) {
+            throw new AmqpNotFoundException("exchange not found");
+        }
+        return exchangeInfo.isQueueBindingExist(queue);
+    }
+
+    @Override
+    public boolean checkExist(String virtualHostName, String exchangeName) {
+        ExchangeInfo exchangeInfo = getExchange(virtualHostName, exchangeName);
+        return exchangeInfo != null;
+    }
+
+    @Override
+    public Set<String> getExchangeList(String virtualHostName) throws Exception {
+        ConcurrentHashMap<String, ExchangeInfo> map = exchangeMapping.get(virtualHostName);
+        if (map != null) {
+            return map.keySet();
+        }
+        return new HashSet<>();
+    }
+}


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