This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new fbbb81de1 [ISSUE #4403] Fix redis admin spi (#4405)
fbbb81de1 is described below
commit fbbb81de18bddd42bd2b10e15c4b88210218b7fa
Author: Fabian Bao <[email protected]>
AuthorDate: Tue Aug 29 20:47:13 2023 +0800
[ISSUE #4403] Fix redis admin spi (#4405)
* feat: fix redis admin spi.
* feat: fix redis admin spi.
* feat: fix redis admin spi.
* feat: fix redis admin spi.
* feat: fix redis admin spi.
---
.../eventmesh/storage/redis/admin/RedisAdmin.java | 69 ++++++++++++++++++
.../storage/redis/admin/RedisAdminAdaptor.java | 85 ++++++++++++++++++++++
.../storage/redis/consumer/RedisConsumer.java | 1 -
.../org.apache.eventmesh.api.admin.Admin} | 3 +-
.../src/main/resources/redis-client.properties | 2 +
5 files changed, 157 insertions(+), 3 deletions(-)
diff --git
a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/admin/RedisAdmin.java
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/admin/RedisAdmin.java
new file mode 100644
index 000000000..3143c134b
--- /dev/null
+++
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/admin/RedisAdmin.java
@@ -0,0 +1,69 @@
+/*
+ * 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.storage.redis.admin;
+
+import org.apache.eventmesh.api.admin.AbstractAdmin;
+import org.apache.eventmesh.api.admin.TopicProperties;
+import org.apache.eventmesh.storage.redis.client.RedissonClient;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+
+import org.redisson.Redisson;
+import org.redisson.api.RPatternTopic;
+import org.redisson.api.RTopic;
+
+import io.cloudevents.CloudEvent;
+
+public class RedisAdmin extends AbstractAdmin {
+
+ private final Redisson redisson;
+
+ public RedisAdmin() {
+ super(new AtomicBoolean(false));
+ redisson = RedissonClient.INSTANCE;
+ }
+
+ @Override
+ public List<TopicProperties> getTopic() throws Exception {
+ // TODO: match all the topic with pattern "*" for now.
+ RPatternTopic patternTopic = redisson.getPatternTopic("*");
+ return patternTopic.getPatternNames()
+ .stream()
+ .map(s -> new TopicProperties(s, 0))
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public void createTopic(String topicName) throws Exception {
+ // Just subscribe it directly, no need to create it first.
+ }
+
+ @Override
+ public void deleteTopic(String topicName) throws Exception {
+ RTopic topic = redisson.getTopic(topicName);
+ topic.removeAllListeners();
+ }
+
+ @Override
+ public void publish(CloudEvent cloudEvent) throws Exception {
+ RTopic topic = redisson.getTopic(cloudEvent.getSubject());
+ topic.publish(cloudEvent);
+ }
+}
diff --git
a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/admin/RedisAdminAdaptor.java
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/admin/RedisAdminAdaptor.java
new file mode 100644
index 000000000..7275fc70b
--- /dev/null
+++
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/admin/RedisAdminAdaptor.java
@@ -0,0 +1,85 @@
+/*
+ * 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.storage.redis.admin;
+
+import org.apache.eventmesh.api.admin.Admin;
+import org.apache.eventmesh.api.admin.TopicProperties;
+
+import java.util.List;
+import java.util.Properties;
+
+import io.cloudevents.CloudEvent;
+
+public class RedisAdminAdaptor implements Admin {
+
+ private final RedisAdmin admin;
+
+ public RedisAdminAdaptor() {
+ admin = new RedisAdmin();
+ }
+
+ @Override
+ public boolean isStarted() {
+ return admin.isStarted();
+ }
+
+ @Override
+ public boolean isClosed() {
+ return admin.isClosed();
+ }
+
+ @Override
+ public void start() {
+ admin.start();
+ }
+
+ @Override
+ public void shutdown() {
+ admin.shutdown();
+ }
+
+ @Override
+ public void init(Properties properties) throws Exception {
+ admin.init(properties);
+ }
+
+ @Override
+ public List<TopicProperties> getTopic() throws Exception {
+ return admin.getTopic();
+ }
+
+ @Override
+ public void createTopic(String topicName) throws Exception {
+ admin.createTopic(topicName);
+ }
+
+ @Override
+ public void deleteTopic(String topicName) throws Exception {
+ admin.deleteTopic(topicName);
+ }
+
+ @Override
+ public List<CloudEvent> getEvent(String topicName, int offset, int length)
throws Exception {
+ return admin.getEvent(topicName, offset, length);
+ }
+
+ @Override
+ public void publish(CloudEvent cloudEvent) throws Exception {
+ admin.publish(cloudEvent);
+ }
+}
\ No newline at end of file
diff --git
a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/consumer/RedisConsumer.java
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/consumer/RedisConsumer.java
index 8cc33bfd0..1bac0f145 100644
---
a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/consumer/RedisConsumer.java
+++
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/consumer/RedisConsumer.java
@@ -39,7 +39,6 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class RedisConsumer implements Consumer {
-
private Redisson redisson;
private EventMeshMessageListener messageListener;
diff --git
a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/redis-client.properties
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.admin.Admin
similarity index 92%
copy from
eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/redis-client.properties
copy to
eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.admin.Admin
index 622297217..cc86b755f 100644
---
a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/redis-client.properties
+++
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.api.admin.Admin
@@ -1,4 +1,3 @@
-#
# 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.
@@ -13,5 +12,5 @@
# 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.
-#
+redis=org.apache.eventmesh.storage.redis.admin.RedisAdminAdaptor
\ No newline at end of file
diff --git
a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/redis-client.properties
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/redis-client.properties
index 622297217..e024dca8a 100644
---
a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/redis-client.properties
+++
b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/resources/redis-client.properties
@@ -15,3 +15,5 @@
# limitations under the License.
#
+eventMesh.server.redis.serverAddress=
+eventMesh.server.redis.serverPassword=
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]