pandaapo commented on code in PR #4578:
URL: https://github.com/apache/eventmesh/pull/4578#discussion_r1404369019


##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/FilterEngine.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.boot;
+
+import org.apache.eventmesh.api.meta.MetaServiceListener;
+import org.apache.eventmesh.common.utils.JsonUtils;
+import org.apache.eventmesh.common.utils.LogUtils;
+import org.apache.eventmesh.filter.pattern.Pattern;
+import org.apache.eventmesh.filter.patternbuild.PatternBuilder;
+import 
org.apache.eventmesh.runtime.core.protocol.http.consumer.ConsumerGroupManager;
+import 
org.apache.eventmesh.runtime.core.protocol.http.consumer.ConsumerManager;
+import org.apache.eventmesh.runtime.core.protocol.producer.EventMeshProducer;
+import org.apache.eventmesh.runtime.core.protocol.producer.ProducerManager;
+import org.apache.eventmesh.runtime.meta.MetaStorage;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class FilterEngine {
+
+    /**
+     * key:group-topic
+     **/
+    private final Map<String, Pattern> filterPatternMap = new HashMap<>();
+
+    private final String filterPrefix = "filter-";
+
+    private final MetaStorage metaStorage;
+
+    private MetaServiceListener metaServiceListener;
+
+    private final ProducerManager producerManager;
+
+    private final ConsumerManager consumerManager;
+
+    private final ScheduledExecutorService scheduledExecutorService = 
Executors.newSingleThreadScheduledExecutor();
+
+    public FilterEngine(MetaStorage metaStorage, ProducerManager 
producerManager, ConsumerManager consumerManager) {
+        this.metaStorage = metaStorage;
+        this.producerManager = producerManager;
+        this.consumerManager = consumerManager;
+    }
+
+    public void start() {
+        Map<String, String> filterMetaData = 
metaStorage.getMetaData(filterPrefix, true);
+        for (Entry<String, String> filterDataEntry : 
filterMetaData.entrySet()) {
+            // filter-group
+            String key = filterDataEntry.getKey();
+            // topic-filterRule list
+            String value = filterDataEntry.getValue();
+            updateFilterPatternMap(key, value);
+        }
+        metaServiceListener = this::updateFilterPatternMap;
+
+        // addListeners for producerManager & consumerManager
+        scheduledExecutorService.scheduleAtFixedRate(() -> {

Review Comment:
   There is one more issue, and I haven't figured out for now how to handle it. 
Perhaps a note can be made and optimize it later if it's worthy. Can expired or 
obsolete rules be detected locally, and then the corresponding rules in the 
remote configuration can be deleted? This can save some manual management of 
remote configuration work and control the traversal here as effectively as 
possible.
   
   
还有一个问题,但我暂时没想到怎么处理,如果有价值也许可以备注一下后期再优化。需不需要从本地检测出已经失效或过时的规则,然后删除远程配置中对应的规则?这样可以省去一部分手动管理远程配置的工作,也可以控制这里的遍历尽量有效。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to