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 05:52:34 UTC
[incubator-eventmesh] branch protocol-amqp updated: realization amqp queue 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 98a8310a realization amqp queue manager
new 63ae270b Merge pull request #1589 from wangshaojie4039/protocol-amqp
98a8310a is described below
commit 98a8310a82dffe691e93ca51db7d326c7350e4fc
Author: wangshaojie <wa...@cmss.chinamobile.com>
AuthorDate: Sat Oct 15 13:29:28 2022 +0800
realization amqp queue manager
---
.../amqp/exception/AmqpNotFoundException.java | 31 ++++++
.../amqp/metadata/manager/QueueManager.java | 50 ++++++++++
.../metadata/manager/QueueManagerMemoryImpl.java | 110 +++++++++++++++++++++
.../protocol/amqp/metadata/model/QueueInfo.java | 101 +++++++++++++++++++
4 files changed, 292 insertions(+)
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/exception/AmqpNotFoundException.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/exception/AmqpNotFoundException.java
new file mode 100644
index 00000000..563b4ff7
--- /dev/null
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/exception/AmqpNotFoundException.java
@@ -0,0 +1,31 @@
+/*
+ * 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.exception;
+
+public class AmqpNotFoundException extends Exception {
+
+ public AmqpNotFoundException() {
+ }
+
+ public AmqpNotFoundException(String message) {
+ super(message);
+ }
+
+ public AmqpNotFoundException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/QueueManager.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/QueueManager.java
new file mode 100644
index 00000000..d6464060
--- /dev/null
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/QueueManager.java
@@ -0,0 +1,50 @@
+/*
+ * 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.QueueInfo;
+
+import java.util.Set;
+
+public interface QueueManager {
+
+ void createQueue(String virtualHostName, final String queueName, QueueInfo meta) throws AmqpNotFoundException;
+
+
+ QueueInfo getQueue(String virtualHostName, final String queueName);
+
+ void deleteQueue(String virtualHostName, final String queueName);
+
+
+ void queueBind(String virtualHostName, String queue, String exchangeName) throws AmqpNotFoundException;
+
+
+ void queueUnBind(String virtualHostName, final String queue,
+ String exchangeName) throws AmqpNotFoundException;
+
+
+ void queueUnBindAll(String virtualHostName, final String queue) throws AmqpNotFoundException;
+
+ boolean checkExist(String virtualHostName, final String queue);
+
+ Set<String> getQueueList(String virtualHostName);
+
+ Set<String> getBindings(String virtualHostName, String queue);
+
+}
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/QueueManagerMemoryImpl.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/QueueManagerMemoryImpl.java
new file mode 100644
index 00000000..45f042dc
--- /dev/null
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/manager/QueueManagerMemoryImpl.java
@@ -0,0 +1,110 @@
+/*
+ * 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.QueueInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class QueueManagerMemoryImpl implements QueueManager {
+
+ private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
+
+ private ConcurrentHashMap<String, ConcurrentHashMap<String, QueueInfo>> queueMapping = new ConcurrentHashMap<>();
+
+
+ @Override
+ public void createQueue(String virtualHostName, String queueName, QueueInfo meta) throws AmqpNotFoundException {
+ ConcurrentHashMap<String, QueueInfo> infoMap = queueMapping.computeIfAbsent(virtualHostName, m -> new ConcurrentHashMap<>());
+ if (infoMap == null) {
+ log.error("virtualHost not found {}", virtualHostName);
+ throw new AmqpNotFoundException("vhost not found");
+ }
+ if (!infoMap.containsKey(queueName)) {
+ infoMap.put(queueName, meta);
+ }
+ }
+
+
+ @Override
+ public QueueInfo getQueue(String virtualHostName, String queueName) {
+ ConcurrentHashMap<String, QueueInfo> map = queueMapping.get(virtualHostName);
+ if (map != null) {
+ return map.get(queueName);
+ }
+ return null;
+ }
+
+ @Override
+ public void deleteQueue(String virtualHostName, String queueName) {
+ ConcurrentHashMap<String, QueueInfo> map = queueMapping.get(virtualHostName);
+ if (map != null) {
+ map.remove(queueName);
+ }
+ }
+
+ @Override
+ public void queueBind(String virtualHostName, String queue, String exchangeName) throws AmqpNotFoundException {
+ QueueInfo queueInfo = getQueue(virtualHostName, queue);
+ if (queueInfo == null) {
+ throw new AmqpNotFoundException("queue not found");
+ }
+ queueInfo.addBinding(exchangeName);
+ }
+
+ @Override
+ public void queueUnBind(String virtualHostName, String queue, String exchangeName) throws AmqpNotFoundException {
+ QueueInfo queueInfo = getQueue(virtualHostName, queue);
+ if (queueInfo == null) {
+ throw new AmqpNotFoundException("queue not found");
+ }
+ queueInfo.removeBinding(exchangeName);
+ }
+
+ @Override
+ public void queueUnBindAll(String virtualHostName, String queue) throws AmqpNotFoundException {
+ QueueInfo queueInfo = getQueue(virtualHostName, queue);
+ if (queueInfo == null) {
+ throw new AmqpNotFoundException("queue not found");
+ }
+ queueInfo.removeAll();
+ }
+
+ @Override
+ public boolean checkExist(String virtualHostName, String queue) {
+ return getQueue(virtualHostName, queue) != null;
+ }
+
+ @Override
+ public Set<String> getQueueList(String virtualHostName) {
+ return queueMapping.get(virtualHostName).keySet();
+ }
+
+ @Override
+ public Set<String> getBindings(String virtualHost, String queue) {
+ QueueInfo queueInfo = getQueue(virtualHost, queue);
+ if (queueInfo != null) {
+ return queueInfo.getExchanges();
+ }
+ return null;
+ }
+}
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/model/QueueInfo.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/model/QueueInfo.java
new file mode 100644
index 00000000..38492b7d
--- /dev/null
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/amqp/metadata/model/QueueInfo.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.model;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+public class QueueInfo {
+
+ private String creationDate;
+ private long lastVisitTime;
+
+ private String queueName;
+ private boolean durable;
+ private boolean autoDelete;
+ private boolean exclusive;
+ private String connectionId;
+ private Map<String, String> arguments;
+ private Set<String> exchanges;
+
+ public void setQueueName(String queueName) {
+ this.queueName = queueName;
+ }
+
+ public void setDurable(boolean durable) {
+ this.durable = durable;
+ }
+
+ public void setAutoDelete(boolean autoDelete) {
+ this.autoDelete = autoDelete;
+ }
+
+ public void setExclusive(boolean exclusive) {
+ this.exclusive = exclusive;
+ }
+
+ public void setConnectionId(String connectionId) {
+ this.connectionId = connectionId;
+ }
+
+ public void setArguments(Map<String, String> arguments) {
+ this.arguments = arguments;
+ }
+
+ public void setLastVisitTime(long lastVisitTime) {
+ this.lastVisitTime = lastVisitTime;
+ }
+
+ public String getQueueName() {
+ return queueName;
+ }
+
+ public boolean isDurable() {
+ return durable;
+ }
+
+ public boolean isAutoDelete() {
+ return autoDelete;
+ }
+
+ public boolean isExclusive() {
+ return exclusive;
+ }
+
+ public String getConnectionId() {
+ return connectionId;
+ }
+
+ public Map<String, String> getArguments() {
+ return arguments;
+ }
+
+ public Set<String> getExchanges() {
+ Set<String> set = new HashSet<>();
+ set.addAll(exchanges);
+ return set;
+ }
+
+ public synchronized void addBinding(String exchange) {
+ exchanges.add(exchange);
+ }
+
+ public synchronized void removeBinding(String exchange) {
+ exchanges.remove(exchange);
+ }
+
+ public synchronized void removeAll() {
+ exchanges.clear();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org