xwm1992 commented on code in PR #4578: URL: https://github.com/apache/eventmesh/pull/4578#discussion_r1405334799
########## 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: The timing task is currently configured based on the groups of the producer manager and the consumer manager. Because the remote configuration center needs to be configured based on the group, the actual rule effectiveness also depends on whether these groups exist. It only applies to groups that exist in the mesh. The monitoring function of configured rules is implemented, and the active pull task is not performed. The active pull can only perform a fuzzy matching rule pull after starting the mesh. --- 这个定时任务目前是根据producerManager与consumerManager的group进行的配置监听,因为远程配置中心需要根据group来配置,实际上规则生效也取决于是否存在这些group,因此只对mesh中存在的group做了规则配置的监听功能,没有做主动拉取任务,主动拉取只会在启动mesh后进行一次模糊匹配的规则拉取 ########## 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: The timing task is currently configured based on the groups of the producer manager and the consumer manager. Because the remote configuration center needs to be configured based on the group, the actual rule effectiveness also depends on whether these groups exist. It only applies to groups that exist in the mesh. The monitoring function of configured rules is implemented, and the active pull task is not performed. The active pull can only perform a fuzzy matching rule pull after starting the mesh. --- 这个定时任务目前是根据producerManager与consumerManager的group进行的配置监听,因为远程配置中心需要根据group来配置,实际上规则生效也取决于是否存在这些group,因此只对mesh中存在的group做了规则配置的监听功能,没有做主动拉取任务,主动拉取只会在启动mesh后进行一次模糊匹配的规则拉取 -- 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]
