You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by "eurecalulu (via GitHub)" <gi...@apache.org> on 2023/09/30 15:43:25 UTC
[GitHub] [shenyu] eurecalulu opened a new pull request, #5193: [type: feature] add nacos, etcd, eureka discovery service
eurecalulu opened a new pull request, #5193:
URL: https://github.com/apache/shenyu/pull/5193
Because OSPP requires a submission before September 30, I will submit a PR first. I'll add more later as I haven't passed all the tests yet.
Make sure that:
- [ ] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide).
- [ ] You submit test cases (unit or integration tests) that back your changes.
- [ ] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`.
--
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: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shenyu] codecov-commenter commented on pull request #5193: [type: feature] add nacos, etcd, eureka discovery service
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #5193:
URL: https://github.com/apache/shenyu/pull/5193#issuecomment-1741843545
## [Codecov](https://app.codecov.io/gh/apache/shenyu/pull/5193?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#5193](https://app.codecov.io/gh/apache/shenyu/pull/5193?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (981085c) into [master](https://app.codecov.io/gh/apache/shenyu/commit/a9ca7fd5e3f8ea494d0e3bf9d06dac52f60fa967?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (a9ca7fd) will **decrease** coverage by `0.12%`.
> The diff coverage is `0.00%`.
```diff
@@ Coverage Diff @@
## master #5193 +/- ##
============================================
- Coverage 61.90% 61.79% -0.12%
+ Complexity 8579 8567 -12
============================================
Files 1244 1244
Lines 37631 37624 -7
Branches 3557 3555 -2
============================================
- Hits 23296 23248 -48
- Misses 12302 12342 +40
- Partials 2033 2034 +1
```
| [Files](https://app.codecov.io/gh/apache/shenyu/pull/5193?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...g/apache/shenyu/admin/discovery/DiscoveryMode.java](https://app.codecov.io/gh/apache/shenyu/pull/5193?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2hlbnl1LWFkbWluL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGVueXUvYWRtaW4vZGlzY292ZXJ5L0Rpc2NvdmVyeU1vZGUuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...nyu/admin/discovery/DefaultDiscoveryProcessor.java](https://app.codecov.io/gh/apache/shenyu/pull/5193?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2hlbnl1LWFkbWluL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGVueXUvYWRtaW4vZGlzY292ZXJ5L0RlZmF1bHREaXNjb3ZlcnlQcm9jZXNzb3IuamF2YQ==) | `10.30% <0.00%> (ø)` | |
| [...enyu/admin/discovery/DiscoveryProcessorHolder.java](https://app.codecov.io/gh/apache/shenyu/pull/5193?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2hlbnl1LWFkbWluL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGVueXUvYWRtaW4vZGlzY292ZXJ5L0Rpc2NvdmVyeVByb2Nlc3NvckhvbGRlci5qYXZh) | `26.66% <0.00%> (-17.78%)` | :arrow_down: |
... and [35 files with indirect coverage changes](https://app.codecov.io/gh/apache/shenyu/pull/5193/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
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: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type: feature] add nacos, etcd, eureka discovery service [shenyu]
Posted by "eurecalulu (via GitHub)" <gi...@apache.org>.
eurecalulu commented on code in PR #5193:
URL: https://github.com/apache/shenyu/pull/5193#discussion_r1353839458
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/DefaultDiscoveryProcessor.java:
##########
@@ -176,6 +176,7 @@ public void fetchAll(final String discoveryHandlerId) {
String discoveryId = discoveryHandlerDO.getDiscoveryId();
if (discoveryServiceCache.containsKey(discoveryId)) {
ShenyuDiscoveryService shenyuDiscoveryService = discoveryServiceCache.get(discoveryId);
+ // TODO 如果列表为空?
Review Comment:
Thank you for your review, I will modify it immediately.
--
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: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type: feature] add nacos, etcd, eureka discovery service [shenyu]
Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind merged PR #5193:
URL: https://github.com/apache/shenyu/pull/5193
--
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: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type: feature] add nacos, etcd, eureka discovery service [shenyu]
Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on code in PR #5193:
URL: https://github.com/apache/shenyu/pull/5193#discussion_r1353823696
##########
shenyu-discovery/shenyu-discovery-eureka/src/main/java/org/apache/shenyu/discovery/eureka/EurekaDiscoveryService.java:
##########
@@ -0,0 +1,252 @@
+/*
+ * 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.shenyu.discovery.eureka;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.netflix.appinfo.ApplicationInfoManager;
+import com.netflix.appinfo.MyDataCenterInstanceConfig;
+import com.netflix.appinfo.InstanceInfo;
+import com.netflix.appinfo.DataCenterInfo;
+import com.netflix.appinfo.MyDataCenterInfo;
+import com.netflix.appinfo.EurekaInstanceConfig;
+import com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider;
+import com.netflix.config.ConfigurationManager;
+import com.netflix.discovery.EurekaClient;
+import com.netflix.discovery.EurekaClientConfig;
+import com.netflix.discovery.DiscoveryClient;
+import com.netflix.discovery.DefaultEurekaClientConfig;
+import com.netflix.discovery.shared.transport.EurekaHttpClient;
+import com.netflix.discovery.shared.transport.jersey.JerseyApplicationClient;
+import com.sun.jersey.client.apache4.ApacheHttpClient4;
+import org.apache.shenyu.common.exception.ShenyuException;
+import org.apache.shenyu.discovery.api.listener.DiscoveryDataChangedEvent;
+import org.apache.shenyu.spi.Join;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.shenyu.discovery.api.ShenyuDiscoveryService;
+import org.apache.shenyu.discovery.api.config.DiscoveryConfig;
+import org.apache.shenyu.discovery.api.listener.DataChangedEventListener;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@Join
+public class EurekaDiscoveryService implements ShenyuDiscoveryService {
+ private static final Logger LOGGER = LoggerFactory.getLogger(EurekaDiscoveryService.class);
+
+ private ApplicationInfoManager applicationInfoManager;
+
+ private EurekaClient eurekaClient;
+
+ private EurekaHttpClient eurekaHttpClient;
+
+ private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
Review Comment:
not use Executors create thread pool
--
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: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type: feature] add nacos, etcd, eureka discovery service [shenyu]
Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on code in PR #5193:
URL: https://github.com/apache/shenyu/pull/5193#discussion_r1353813117
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/DefaultDiscoveryProcessor.java:
##########
@@ -176,6 +176,7 @@ public void fetchAll(final String discoveryHandlerId) {
String discoveryId = discoveryHandlerDO.getDiscoveryId();
if (discoveryServiceCache.containsKey(discoveryId)) {
ShenyuDiscoveryService shenyuDiscoveryService = discoveryServiceCache.get(discoveryId);
+ // TODO 如果列表为空?
Review Comment:
remove this
##########
shenyu-discovery/shenyu-discovery-api/src/main/java/org/apache/shenyu/discovery/api/ShenyuDiscoveryService.java:
##########
@@ -62,18 +62,18 @@ public interface ShenyuDiscoveryService {
/**
* getData by key.
*
- * @param key key
+ * @param key keyd
Review Comment:
key
##########
shenyu-discovery/shenyu-discovery-etcd/src/main/java/org/apache/shenyu/discovery/etcd/EtcdDiscoveryService.java:
##########
@@ -0,0 +1,210 @@
+/*
+ * 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.shenyu.discovery.etcd;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.KV;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.kv.GetResponse;
+import io.etcd.jetcd.lease.LeaseKeepAliveResponse;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.watch.WatchEvent;
+import io.grpc.stub.StreamObserver;
+import org.apache.shenyu.common.exception.ShenyuException;
+import org.apache.shenyu.discovery.api.ShenyuDiscoveryService;
+import org.apache.shenyu.discovery.api.config.DiscoveryConfig;
+import org.apache.shenyu.discovery.api.listener.DataChangedEventListener;
+import org.apache.shenyu.discovery.api.listener.DiscoveryDataChangedEvent;
+import org.apache.shenyu.spi.Join;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+@Join
+public class EtcdDiscoveryService implements ShenyuDiscoveryService {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(EtcdDiscoveryService.class);
+
+ private Client etcdClient;
+
+ private final ConcurrentMap<String, Watch.Watcher> watchCache = new ConcurrentHashMap<>();
+
+ private long leaseId;
+
+ private long ttl;
+
+ private long timeout;
+
+ @Override
+ public void init(final DiscoveryConfig config) {
+ Properties props = config.getProps();
+ this.timeout = Long.parseLong(props.getProperty("etcdTimeout", "3000"));
+ this.ttl = Long.parseLong(props.getProperty("etcdTTL", "5"));
+ if (this.etcdClient == null) {
Review Comment:
use Objects.isNull
##########
shenyu-discovery/shenyu-discovery-eureka/src/main/java/org/apache/shenyu/discovery/eureka/EurekaDiscoveryService.java:
##########
@@ -0,0 +1,252 @@
+/*
+ * 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.shenyu.discovery.eureka;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.netflix.appinfo.ApplicationInfoManager;
+import com.netflix.appinfo.MyDataCenterInstanceConfig;
+import com.netflix.appinfo.InstanceInfo;
+import com.netflix.appinfo.DataCenterInfo;
+import com.netflix.appinfo.MyDataCenterInfo;
+import com.netflix.appinfo.EurekaInstanceConfig;
+import com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider;
+import com.netflix.config.ConfigurationManager;
+import com.netflix.discovery.EurekaClient;
+import com.netflix.discovery.EurekaClientConfig;
+import com.netflix.discovery.DiscoveryClient;
+import com.netflix.discovery.DefaultEurekaClientConfig;
+import com.netflix.discovery.shared.transport.EurekaHttpClient;
+import com.netflix.discovery.shared.transport.jersey.JerseyApplicationClient;
+import com.sun.jersey.client.apache4.ApacheHttpClient4;
+import org.apache.shenyu.common.exception.ShenyuException;
+import org.apache.shenyu.discovery.api.listener.DiscoveryDataChangedEvent;
+import org.apache.shenyu.spi.Join;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.shenyu.discovery.api.ShenyuDiscoveryService;
+import org.apache.shenyu.discovery.api.config.DiscoveryConfig;
+import org.apache.shenyu.discovery.api.listener.DataChangedEventListener;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@Join
+public class EurekaDiscoveryService implements ShenyuDiscoveryService {
+ private static final Logger LOGGER = LoggerFactory.getLogger(EurekaDiscoveryService.class);
+
+ private ApplicationInfoManager applicationInfoManager;
+
+ private EurekaClient eurekaClient;
+
+ private EurekaHttpClient eurekaHttpClient;
+
+ private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
+
+ private final ConcurrentMap<String, ScheduledFuture<?>> listenerThreadsMap = new ConcurrentHashMap<>();
+
+ private final ConcurrentMap<String, List<InstanceInfo>> instanceListMap = new ConcurrentHashMap<>();
+
+ @Override
+ public void init(final DiscoveryConfig config) {
+ try {
+ if (eurekaClient == null) {
+ ConfigurationManager.loadProperties(getEurekaProperties(config));
+ applicationInfoManager = initializeApplicationInfoManager(new MyDataCenterInstanceConfig());
+ eurekaClient = initializeEurekaClient(applicationInfoManager, new DefaultEurekaClientConfig());
+ eurekaHttpClient = new JerseyApplicationClient(new ApacheHttpClient4(), config.getServerList(), null);
+ }
+ } catch (Exception e) {
+ clean();
+ throw new ShenyuException(e);
+ }
+ }
+
+ @Override
+ public void watch(final String key, final DataChangedEventListener listener) {
+ if (!listenerThreadsMap.containsKey(key)) {
+ List<InstanceInfo> initialInstances = eurekaClient.getInstancesByVipAddressAndAppName(null, key, true);
+ instanceListMap.put(key, initialInstances);
+ ScheduledFuture<?> scheduledFuture = executorService.scheduleAtFixedRate(() -> {
+ try {
+ List<InstanceInfo> previousInstances = instanceListMap.get(key);
+ List<InstanceInfo> currentInstances = eurekaClient.getInstancesByVipAddressAndAppName(null, key, true);
+ compareInstances(previousInstances, currentInstances, listener);
+ instanceListMap.put(key, currentInstances);
+ } catch (Exception e) {
+ throw new ShenyuException(e);
+ }
+ }, 0, 1, TimeUnit.SECONDS);
+ listenerThreadsMap.put(key, scheduledFuture);
+ }
+ }
+
+ @Override
+ public void unwatch(final String key) {
+ try {
+ ScheduledFuture<?> scheduledFuture = listenerThreadsMap.get(key);
+ if (scheduledFuture != null) {
Review Comment:
Objects.isNull
##########
shenyu-discovery/shenyu-discovery-etcd/pom.xml:
##########
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-discovery</artifactId>
+ <version>2.6.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>shenyu-discovery-etcd</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-discovery-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-common</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+<!-- <dependency>-->
Review Comment:
remove this
##########
shenyu-discovery/shenyu-discovery-eureka/src/main/java/org/apache/shenyu/discovery/eureka/EurekaDiscoveryService.java:
##########
@@ -0,0 +1,252 @@
+/*
+ * 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.shenyu.discovery.eureka;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.netflix.appinfo.ApplicationInfoManager;
+import com.netflix.appinfo.MyDataCenterInstanceConfig;
+import com.netflix.appinfo.InstanceInfo;
+import com.netflix.appinfo.DataCenterInfo;
+import com.netflix.appinfo.MyDataCenterInfo;
+import com.netflix.appinfo.EurekaInstanceConfig;
+import com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider;
+import com.netflix.config.ConfigurationManager;
+import com.netflix.discovery.EurekaClient;
+import com.netflix.discovery.EurekaClientConfig;
+import com.netflix.discovery.DiscoveryClient;
+import com.netflix.discovery.DefaultEurekaClientConfig;
+import com.netflix.discovery.shared.transport.EurekaHttpClient;
+import com.netflix.discovery.shared.transport.jersey.JerseyApplicationClient;
+import com.sun.jersey.client.apache4.ApacheHttpClient4;
+import org.apache.shenyu.common.exception.ShenyuException;
+import org.apache.shenyu.discovery.api.listener.DiscoveryDataChangedEvent;
+import org.apache.shenyu.spi.Join;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.shenyu.discovery.api.ShenyuDiscoveryService;
+import org.apache.shenyu.discovery.api.config.DiscoveryConfig;
+import org.apache.shenyu.discovery.api.listener.DataChangedEventListener;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@Join
+public class EurekaDiscoveryService implements ShenyuDiscoveryService {
+ private static final Logger LOGGER = LoggerFactory.getLogger(EurekaDiscoveryService.class);
+
+ private ApplicationInfoManager applicationInfoManager;
+
+ private EurekaClient eurekaClient;
+
+ private EurekaHttpClient eurekaHttpClient;
+
+ private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
+
+ private final ConcurrentMap<String, ScheduledFuture<?>> listenerThreadsMap = new ConcurrentHashMap<>();
+
+ private final ConcurrentMap<String, List<InstanceInfo>> instanceListMap = new ConcurrentHashMap<>();
+
+ @Override
+ public void init(final DiscoveryConfig config) {
+ try {
+ if (eurekaClient == null) {
+ ConfigurationManager.loadProperties(getEurekaProperties(config));
+ applicationInfoManager = initializeApplicationInfoManager(new MyDataCenterInstanceConfig());
+ eurekaClient = initializeEurekaClient(applicationInfoManager, new DefaultEurekaClientConfig());
+ eurekaHttpClient = new JerseyApplicationClient(new ApacheHttpClient4(), config.getServerList(), null);
+ }
+ } catch (Exception e) {
+ clean();
+ throw new ShenyuException(e);
+ }
+ }
+
+ @Override
+ public void watch(final String key, final DataChangedEventListener listener) {
+ if (!listenerThreadsMap.containsKey(key)) {
+ List<InstanceInfo> initialInstances = eurekaClient.getInstancesByVipAddressAndAppName(null, key, true);
+ instanceListMap.put(key, initialInstances);
+ ScheduledFuture<?> scheduledFuture = executorService.scheduleAtFixedRate(() -> {
+ try {
+ List<InstanceInfo> previousInstances = instanceListMap.get(key);
+ List<InstanceInfo> currentInstances = eurekaClient.getInstancesByVipAddressAndAppName(null, key, true);
+ compareInstances(previousInstances, currentInstances, listener);
+ instanceListMap.put(key, currentInstances);
+ } catch (Exception e) {
+ throw new ShenyuException(e);
Review Comment:
add Log.error("watch discovery data error=", e)
##########
shenyu-discovery/shenyu-discovery-nacos/pom.xml:
##########
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-discovery</artifactId>
+ <version>2.6.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>shenyu-discovery-nacos</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-discovery-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-common</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba.fastjson2</groupId>
+ <artifactId>fastjson2</artifactId>
+ <version>2.0.14</version>
Review Comment:
remove this
##########
shenyu-discovery/shenyu-discovery-eureka/pom.xml:
##########
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-discovery</artifactId>
+ <version>2.6.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>shenyu-discovery-eureka</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-discovery-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-common</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.netflix.eureka</groupId>
+ <artifactId>eureka-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba.fastjson2</groupId>
+ <artifactId>fastjson2</artifactId>
+ <version>2.0.14</version>
Review Comment:
not use fastjson
--
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: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type: feature] add nacos, etcd, eureka discovery service [shenyu]
Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on code in PR #5193:
URL: https://github.com/apache/shenyu/pull/5193#discussion_r1375437832
##########
pom.xml:
##########
@@ -197,12 +197,6 @@
<scope>import</scope>
</dependency>
- <dependency>
- <groupId>com.alibaba.nacos</groupId>
Review Comment:
why remove this? this is dependency management
--
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: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org