You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2022/10/13 10:28:22 UTC
[shenyu] branch master updated: [type:feat] Modify shenyu sdk and add shenyu.sdk.enable (#4060)
This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 9c4f8af57 [type:feat] Modify shenyu sdk and add shenyu.sdk.enable (#4060)
9c4f8af57 is described below
commit 9c4f8af57e737de63d9e5e210bb881c7c593299b
Author: yunlongn <yu...@outlook.com>
AuthorDate: Thu Oct 13 18:28:12 2022 +0800
[type:feat] Modify shenyu sdk and add shenyu.sdk.enable (#4060)
* [type:feat] modify sdk starter and add ShenyuInstanceRegisterRepository bean .
* [type:feat] modify sdk starter and add ShenyuInstanceRegisterRepository bean .
* [type:feat] modify ShenyuConfig .
* [type:feat] modify InstanceConfig => RegisterConfig .
---
.../src/main/resources/application.yml | 2 +-
.../apache/shenyu/common/config/ShenyuConfig.java | 121 ++++++++++++---------
.../shenyu/common/config/ShenyuConfigTest.java | 4 +-
.../api/ShenyuInstanceRegisterRepository.java | 4 +-
.../consul/ConsulInstanceRegisterRepository.java | 4 +-
.../etcd/EtcdInstanceRegisterRepository.java | 4 +-
.../etcd/EtcdInstanceRegisterRepositoryTest.java | 2 +-
.../nacos/NacosInstanceRegisterRepository.java | 4 +-
.../ZookeeperInstanceRegisterRepository.java | 4 +-
.../ZookeeperInstanceRegisterRepositoryTest.java | 2 +-
.../org/apache/shenyu/sdk/core/ShenyuRequest.java | 17 ++-
.../shenyu/sdk/core/common/RequestTemplate.java | 2 +-
.../starter/instance/InstanceRegisterListener.java | 4 +-
.../instance/ShenyuInstanceConfiguration.java | 4 +-
.../shenyu-spring-boot-starter-sdk/pom.xml | 6 +-
.../starter/sdk/ShenyuClientAutoConfiguration.java | 18 +++
16 files changed, 128 insertions(+), 74 deletions(-)
diff --git a/shenyu-bootstrap/src/main/resources/application.yml b/shenyu-bootstrap/src/main/resources/application.yml
index de8954762..f61c5bcdd 100644
--- a/shenyu-bootstrap/src/main/resources/application.yml
+++ b/shenyu-bootstrap/src/main/resources/application.yml
@@ -147,7 +147,7 @@ shenyu:
# selectCount: 1
# workerCount: 8
# daemon: true
- instance:
+ register:
enabled: false
registerType: zookeeper #etcd #consul
serverLists: localhost:2181 #http://localhost:2379 #localhost:8848
diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java b/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
index e1c18a3b0..0c5fbc5d7 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
@@ -53,7 +53,9 @@ public class ShenyuConfig {
private CrossFilterConfig cross = new CrossFilterConfig();
- private InstanceConfig instance = new InstanceConfig();
+ private RegisterConfig register = new RegisterConfig();
+
+ private RegisterConfig sdk = new RegisterConfig();
private RibbonConfig ribbon = new RibbonConfig();
@@ -154,25 +156,43 @@ public class ShenyuConfig {
public void setRibbon(final RibbonConfig ribbon) {
this.ribbon = ribbon;
}
-
+
/**
- * Gets instance.
+ * register.
*
- * @return the instance
+ * @return Register
*/
- public InstanceConfig getInstance() {
- return instance;
+ public RegisterConfig getRegister() {
+ return register;
}
-
+
/**
- * Sets instance.
+ * set register.
*
- * @param instance the instance
+ * @param register register
*/
- public void setInstance(final InstanceConfig instance) {
- this.instance = instance;
+ public void setRegister(final RegisterConfig register) {
+ this.register = register;
}
-
+
+ /**
+ * sdk.
+ *
+ * @return Sdk
+ */
+ public RegisterConfig getSdk() {
+ return sdk;
+ }
+
+ /**
+ * set sdk.
+ *
+ * @param sdk sdk
+ */
+ public void setSdk(final RegisterConfig sdk) {
+ this.sdk = sdk;
+ }
+
/**
* Gets switch config.
*
@@ -1241,58 +1261,37 @@ public class ShenyuConfig {
}
}
}
-
- /**
- * The type Instance config.
- */
- public static class InstanceConfig {
-
+
+ public static class RegisterConfig {
+
private boolean enabled;
-
+
private String registerType;
-
+
private String serverLists;
-
+
private Properties props = new Properties();
-
+
/**
- * Instantiates a new Instance config.
+ * RegisterConfig.
*/
- public InstanceConfig() {
-
+ public RegisterConfig() {
+
}
-
+
/**
- * Instantiates a new Instance config.
+ * registerType.
*
* @param registerType the register type
* @param serverLists the server lists
* @param props the props
*/
- public InstanceConfig(final String registerType, final String serverLists, final Properties props) {
+ public RegisterConfig(final String registerType, final String serverLists, final Properties props) {
this.registerType = registerType;
this.serverLists = serverLists;
this.props = props;
}
-
- /**
- * Gets enabled.
- *
- * @return the enabled
- */
- public boolean getEnabled() {
- return enabled;
- }
-
- /**
- * Sets enabled.
- *
- * @param enabled the enabled
- */
- public void setEnabled(final boolean enabled) {
- this.enabled = enabled;
- }
-
+
/**
* getRegisterType.
*
@@ -1301,7 +1300,7 @@ public class ShenyuConfig {
public String getRegisterType() {
return registerType;
}
-
+
/**
* setRegisterType.
*
@@ -1310,7 +1309,7 @@ public class ShenyuConfig {
public void setRegisterType(final String registerType) {
this.registerType = registerType;
}
-
+
/**
* getServerLists.
*
@@ -1319,7 +1318,7 @@ public class ShenyuConfig {
public String getServerLists() {
return serverLists;
}
-
+
/**
* setServerLists.
*
@@ -1328,7 +1327,7 @@ public class ShenyuConfig {
public void setServerLists(final String serverLists) {
this.serverLists = serverLists;
}
-
+
/**
* getProps.
*
@@ -1337,7 +1336,7 @@ public class ShenyuConfig {
public Properties getProps() {
return props;
}
-
+
/**
* setProps.
*
@@ -1346,6 +1345,24 @@ public class ShenyuConfig {
public void setProps(final Properties props) {
this.props = props;
}
+
+ /**
+ * Gets enabled.
+ *
+ * @return the enabled
+ */
+ public boolean getEnabled() {
+ return enabled;
+ }
+
+ /**
+ * Sets enabled.
+ *
+ * @param enabled the enabled
+ */
+ public void setEnabled(final boolean enabled) {
+ this.enabled = enabled;
+ }
}
/**
diff --git a/shenyu-common/src/test/java/org/apache/shenyu/common/config/ShenyuConfigTest.java b/shenyu-common/src/test/java/org/apache/shenyu/common/config/ShenyuConfigTest.java
index ff8da4d3a..aaa1365be 100644
--- a/shenyu-common/src/test/java/org/apache/shenyu/common/config/ShenyuConfigTest.java
+++ b/shenyu-common/src/test/java/org/apache/shenyu/common/config/ShenyuConfigTest.java
@@ -49,7 +49,7 @@ public class ShenyuConfigTest {
ShenyuConfig.ExcludePath exclude = config.getExclude();
ShenyuConfig.FallbackPath fallback = config.getFallback();
ShenyuConfig.FileConfig file = config.getFile();
- ShenyuConfig.InstanceConfig instance = config.getInstance();
+ ShenyuConfig.RegisterConfig instance = config.getRegister();
ShenyuConfig.ExtPlugin extPlugin = config.getExtPlugin();
ShenyuConfig.Local local = config.getLocal();
ShenyuConfig.RibbonConfig ribbon = config.getRibbon();
@@ -187,7 +187,7 @@ public class ShenyuConfigTest {
@Test
public void testInstanceConfig() {
- ShenyuConfig.InstanceConfig instance = config.getInstance();
+ ShenyuConfig.RegisterConfig instance = config.getRegister();
instance.setEnabled(true);
instance.setServerLists("test");
instance.setRegisterType("test");
diff --git a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-api/src/main/java/org/apache/shenyu/register/instance/api/ShenyuInstanceRegisterRepository.java b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-api/src/main/java/org/apache/shenyu/register/instance/api/ShenyuInstanceRegisterRepository.java
index 384137a21..e571b8ba4 100644
--- a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-api/src/main/java/org/apache/shenyu/register/instance/api/ShenyuInstanceRegisterRepository.java
+++ b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-api/src/main/java/org/apache/shenyu/register/instance/api/ShenyuInstanceRegisterRepository.java
@@ -17,7 +17,7 @@
package org.apache.shenyu.register.instance.api;
-import org.apache.shenyu.common.config.ShenyuConfig.InstanceConfig;
+import org.apache.shenyu.common.config.ShenyuConfig.RegisterConfig;
import org.apache.shenyu.register.common.dto.InstanceRegisterDTO;
import org.apache.shenyu.register.common.subsriber.WatcherListener;
import org.apache.shenyu.spi.SPI;
@@ -36,7 +36,7 @@ public interface ShenyuInstanceRegisterRepository {
*
* @param config the config
*/
- default void init(InstanceConfig config) {
+ default void init(RegisterConfig config) {
}
/**
diff --git a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-consul/src/main/java/org/apache/shenyu/register/instance/consul/ConsulInstanceRegisterRepository.java b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-consul/src/main/java/org/apache/shenyu/register/instance/consul/ConsulInstanceRegisterRepository.java
index dbed6a019..28be998b8 100644
--- a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-consul/src/main/java/org/apache/shenyu/register/instance/consul/ConsulInstanceRegisterRepository.java
+++ b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-consul/src/main/java/org/apache/shenyu/register/instance/consul/ConsulInstanceRegisterRepository.java
@@ -19,7 +19,7 @@ package org.apache.shenyu.register.instance.consul;
import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.agent.model.NewCheck;
-import org.apache.shenyu.common.config.ShenyuConfig.InstanceConfig;
+import org.apache.shenyu.common.config.ShenyuConfig.RegisterConfig;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.register.common.dto.InstanceRegisterDTO;
@@ -44,7 +44,7 @@ public class ConsulInstanceRegisterRepository implements ShenyuInstanceRegisterR
private NewCheck check;
@Override
- public void init(final InstanceConfig config) {
+ public void init(final RegisterConfig config) {
final Properties props = config.getProps();
final String timeout = props.getProperty("consulTimeout", "3000");
final String ttl = props.getProperty("consulTTL", "3000");
diff --git a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-etcd/src/main/java/org/apache/shenyu/register/instance/etcd/EtcdInstanceRegisterRepository.java b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-etcd/src/main/java/org/apache/shenyu/register/instance/etcd/EtcdInstanceRegisterRepository.java
index 42a95d72f..eaace23d7 100644
--- a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-etcd/src/main/java/org/apache/shenyu/register/instance/etcd/EtcdInstanceRegisterRepository.java
+++ b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-etcd/src/main/java/org/apache/shenyu/register/instance/etcd/EtcdInstanceRegisterRepository.java
@@ -17,7 +17,7 @@
package org.apache.shenyu.register.instance.etcd;
-import org.apache.shenyu.common.config.ShenyuConfig.InstanceConfig;
+import org.apache.shenyu.common.config.ShenyuConfig.RegisterConfig;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.register.common.dto.InstanceRegisterDTO;
@@ -40,7 +40,7 @@ public class EtcdInstanceRegisterRepository implements ShenyuInstanceRegisterRep
private EtcdClient client;
@Override
- public void init(final InstanceConfig config) {
+ public void init(final RegisterConfig config) {
Properties props = config.getProps();
long timeout = Long.parseLong(props.getProperty("etcdTimeout", "3000"));
long ttl = Long.parseLong(props.getProperty("etcdTTL", "5"));
diff --git a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-etcd/src/test/java/org/apache/shenyu/register/instance/etcd/EtcdInstanceRegisterRepositoryTest.java b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-etcd/src/test/java/org/apache/shenyu/register/instance/etcd/EtcdInstanceRegisterRepositoryTest.java
index 440573f53..5f47ad1ec 100644
--- a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-etcd/src/test/java/org/apache/shenyu/register/instance/etcd/EtcdInstanceRegisterRepositoryTest.java
+++ b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-etcd/src/test/java/org/apache/shenyu/register/instance/etcd/EtcdInstanceRegisterRepositoryTest.java
@@ -110,7 +110,7 @@ public final class EtcdInstanceRegisterRepositoryTest {
when(client.getLeaseClient().grant(anyLong())).thenReturn(completableFuture);
when(completableFuture.get()).thenReturn(leaseGrantResponse);
- final ShenyuConfig.InstanceConfig config = new ShenyuConfig.InstanceConfig();
+ final ShenyuConfig.RegisterConfig config = new ShenyuConfig.RegisterConfig();
config.setServerLists("url");
Assertions.assertDoesNotThrow(() -> repository.init(config));
} catch (Exception e) {
diff --git a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-nacos/src/main/java/org/apache/shenyu/register/instance/nacos/NacosInstanceRegisterRepository.java b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-nacos/src/main/java/org/apache/shenyu/register/instance/nacos/NacosInstanceRegisterRepository.java
index 4c4b34d90..b6527e805 100644
--- a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-nacos/src/main/java/org/apache/shenyu/register/instance/nacos/NacosInstanceRegisterRepository.java
+++ b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-nacos/src/main/java/org/apache/shenyu/register/instance/nacos/NacosInstanceRegisterRepository.java
@@ -22,7 +22,7 @@ import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
-import org.apache.shenyu.common.config.ShenyuConfig.InstanceConfig;
+import org.apache.shenyu.common.config.ShenyuConfig.RegisterConfig;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.exception.ShenyuException;
import org.apache.shenyu.register.common.dto.InstanceRegisterDTO;
@@ -50,7 +50,7 @@ public class NacosInstanceRegisterRepository implements ShenyuInstanceRegisterRe
private String serviceName;
@Override
- public void init(final InstanceConfig config) {
+ public void init(final RegisterConfig config) {
Properties properties = config.getProps();
Properties nacosProperties = new Properties();
this.groupName = properties.getProperty("groupName", "DEFAULT_GROUP");
diff --git a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/main/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperInstanceRegisterRepository.java b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/main/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperInstanceRegisterRepository.java
index 9f869665e..00b51de64 100644
--- a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/main/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperInstanceRegisterRepository.java
+++ b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/main/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperInstanceRegisterRepository.java
@@ -20,7 +20,7 @@ package org.apache.shenyu.register.instance.zookeeper;
import org.apache.commons.lang3.StringUtils;
import org.apache.curator.framework.api.CuratorWatcher;
import org.apache.curator.framework.state.ConnectionState;
-import org.apache.shenyu.common.config.ShenyuConfig.InstanceConfig;
+import org.apache.shenyu.common.config.ShenyuConfig.RegisterConfig;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.register.common.dto.InstanceRegisterDTO;
@@ -55,7 +55,7 @@ public class ZookeeperInstanceRegisterRepository implements ShenyuInstanceRegist
private final Map<String, String> nodeDataMap = new HashMap<>();
@Override
- public void init(final InstanceConfig config) {
+ public void init(final RegisterConfig config) {
Properties props = config.getProps();
int sessionTimeout = Integer.parseInt(props.getProperty("sessionTimeout", "3000"));
int connectionTimeout = Integer.parseInt(props.getProperty("connectionTimeout", "3000"));
diff --git a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/test/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperInstanceRegisterRepositoryTest.java b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/test/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperInstanceRegisterRepositoryTest.java
index 220218922..3e4468959 100644
--- a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/test/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperInstanceRegisterRepositoryTest.java
+++ b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/test/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperInstanceRegisterRepositoryTest.java
@@ -54,7 +54,7 @@ public class ZookeeperInstanceRegisterRepositoryTest {
when(curatorFramework.getConnectionStateListenable()).thenReturn(listenable);
})) {
final ZookeeperInstanceRegisterRepository repository = new ZookeeperInstanceRegisterRepository();
- ShenyuConfig.InstanceConfig config = new ShenyuConfig.InstanceConfig();
+ ShenyuConfig.RegisterConfig config = new ShenyuConfig.RegisterConfig();
repository.init(config);
final Properties configProps = config.getProps();
configProps.setProperty("digest", "digest");
diff --git a/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/ShenyuRequest.java b/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/ShenyuRequest.java
index d04ed95ba..6e5cfec40 100644
--- a/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/ShenyuRequest.java
+++ b/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/ShenyuRequest.java
@@ -34,6 +34,8 @@ public final class ShenyuRequest implements Serializable {
private final String url;
+ private final String contextId;
+
private final Map<String, Collection<String>> headers;
private final String body;
@@ -53,12 +55,14 @@ public final class ShenyuRequest implements Serializable {
final String url,
final Map<String, Collection<String>> headers,
final String body,
+ final String contextId,
final RequestTemplate requestTemplate) {
this.httpMethod = checkNotNull(method, "httpMethod of %s", method.name());
this.url = checkNotNull(url, "url");
this.headers = checkNotNull(headers, "headers of %s %s", method, url);
this.body = body;
this.requestTemplate = requestTemplate;
+ this.contextId = contextId;
}
public enum HttpMethod {
@@ -77,14 +81,16 @@ public final class ShenyuRequest implements Serializable {
* @param headers to include.
* @param body of the request, can be {@literal null}
* @param requestTemplate requestTemplate
+ * @param contextId contextId
* @return a Request
*/
public static ShenyuRequest create(final HttpMethod httpMethod,
final String url,
final Map<String, Collection<String>> headers,
final String body,
+ final String contextId,
final RequestTemplate requestTemplate) {
- return new ShenyuRequest(httpMethod, url, headers, body, requestTemplate);
+ return new ShenyuRequest(httpMethod, url, headers, body, contextId, requestTemplate);
}
/**
@@ -131,4 +137,13 @@ public final class ShenyuRequest implements Serializable {
public RequestTemplate getRequestTemplate() {
return requestTemplate;
}
+
+ /**
+ * getContextId.
+ *
+ * @return {@link String}
+ */
+ public String getContextId() {
+ return contextId;
+ }
}
diff --git a/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/common/RequestTemplate.java b/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/common/RequestTemplate.java
index ebee97605..fcaf7b2f8 100644
--- a/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/common/RequestTemplate.java
+++ b/shenyu-sdk/shenyu-sdk-core/src/main/java/org/apache/shenyu/sdk/core/common/RequestTemplate.java
@@ -79,7 +79,7 @@ public final class RequestTemplate {
* @return {@link ShenyuRequest}
*/
public ShenyuRequest request() {
- return ShenyuRequest.create(this.httpMethod, this.url + this.path, this.headers, this.body, this);
+ return ShenyuRequest.create(this.httpMethod, this.url + this.path, this.headers, this.body, contextId, this);
}
/**
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-instance/src/main/java/org/apache/shenyu/springboot/starter/instance/InstanceRegisterListener.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-instance/src/main/java/org/apache/shenyu/springboot/starter/instance/InstanceRegisterListener.java
index 30bffaaf6..e1aa64e33 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-instance/src/main/java/org/apache/shenyu/springboot/starter/instance/InstanceRegisterListener.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-instance/src/main/java/org/apache/shenyu/springboot/starter/instance/InstanceRegisterListener.java
@@ -18,7 +18,7 @@
package org.apache.shenyu.springboot.starter.instance;
import org.apache.commons.lang3.StringUtils;
-import org.apache.shenyu.common.config.ShenyuConfig.InstanceConfig;
+import org.apache.shenyu.common.config.ShenyuConfig.RegisterConfig;
import org.apache.shenyu.common.exception.ShenyuException;
import org.apache.shenyu.common.utils.IpUtils;
import org.apache.shenyu.register.common.dto.InstanceRegisterDTO;
@@ -50,7 +50,7 @@ public class InstanceRegisterListener implements ApplicationListener<WebServerIn
*
* @param config the config
*/
- public InstanceRegisterListener(final InstanceConfig config) {
+ public InstanceRegisterListener(final RegisterConfig config) {
String registerType = config.getRegisterType();
String serverLists = config.getServerLists();
if (StringUtils.isBlank(registerType) || StringUtils.isBlank(serverLists)) {
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-instance/src/main/java/org/apache/shenyu/springboot/starter/instance/ShenyuInstanceConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-instance/src/main/java/org/apache/shenyu/springboot/starter/instance/ShenyuInstanceConfiguration.java
index 0ab5853f2..3007dcb47 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-instance/src/main/java/org/apache/shenyu/springboot/starter/instance/ShenyuInstanceConfiguration.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-instance/src/main/java/org/apache/shenyu/springboot/starter/instance/ShenyuInstanceConfiguration.java
@@ -35,8 +35,8 @@ public class ShenyuInstanceConfiguration {
* @return the instance register listener
*/
@Bean
- @ConditionalOnProperty(name = "shenyu.instance.enabled", havingValue = "true")
+ @ConditionalOnProperty(name = "shenyu.register.enabled", havingValue = "true")
public InstanceRegisterListener instanceRegisterListener(final ShenyuConfig config) {
- return new InstanceRegisterListener(config.getInstance());
+ return new InstanceRegisterListener(config.getRegister());
}
}
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sdk/pom.xml b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sdk/pom.xml
index 4374853ec..99132fee3 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sdk/pom.xml
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sdk/pom.xml
@@ -27,12 +27,16 @@
<artifactId>shenyu-spring-boot-starter-sdk</artifactId>
<dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-register-instance-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-sdk-spring</artifactId>
<version>${project.version}</version>
</dependency>
-
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sdk/src/main/java/org/apache/shenyu/springboot/starter/sdk/ShenyuClientAutoConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sdk/src/main/java/org/apache/shenyu/springboot/starter/sdk/ShenyuClientAutoConfiguration.java
index c2cbbe4b7..03f97356a 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sdk/src/main/java/org/apache/shenyu/springboot/starter/sdk/ShenyuClientAutoConfiguration.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sdk/src/main/java/org/apache/shenyu/springboot/starter/sdk/ShenyuClientAutoConfiguration.java
@@ -17,7 +17,10 @@
package org.apache.shenyu.springboot.starter.sdk;
+import org.apache.shenyu.common.config.ShenyuConfig;
import org.apache.shenyu.common.exception.ShenyuException;
+import org.apache.shenyu.register.instance.api.ShenyuInstanceRegisterRepository;
+import org.apache.shenyu.register.instance.core.ShenyuInstanceRegisterRepositoryFactory;
import org.apache.shenyu.sdk.core.http.ShenyuHttpClient;
import org.apache.shenyu.sdk.spring.annotation.CookieValueParameterProcessor;
import org.apache.shenyu.sdk.spring.annotation.PathVariableParameterProcessor;
@@ -34,6 +37,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -67,6 +71,20 @@ public class ShenyuClientAutoConfiguration {
};
}
+ /**
+ * ShenYu Instance Register Repository.
+ *
+ * @param config the config
+ * @return ShenYu Instance Register Repository
+ */
+ @Bean
+ @ConditionalOnProperty(name = "shenyu.sdk.enable", havingValue = "true")
+ public ShenyuInstanceRegisterRepository shenyuInstanceRegisterRepository(final ShenyuConfig config) {
+ ShenyuInstanceRegisterRepository repository = ShenyuInstanceRegisterRepositoryFactory.newInstance(config.getSdk().getRegisterType());
+ repository.init(config.getSdk());
+ return repository;
+ }
+
@Configuration(proxyBeanMethods = false)
public static class ParameterProcessorRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
@Override