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 2c9683ca0 [type: refactor] refactor ApacheDubboServiceBeanListener
(#3912)
2c9683ca0 is described below
commit 2c9683ca0d7a71db69ebbe9564e585fae1fb3c92
Author: dragon-zhang <[email protected]>
AuthorDate: Mon Sep 5 11:35:56 2022 +0800
[type: refactor] refactor ApacheDubboServiceBeanListener (#3912)
* [type: refactor] refactor ApacheDubboServiceBeanListener
* fix code style
* fix comment
* fix code style
* fix code style
* fix code style
* fix compile
* fix code style
---
.../AbstractContextRefreshedEventListener.java | 225 +++++++++++++++++++
.../dubbo/ApacheDubboServiceBeanListener.java | 240 +++++++++------------
.../apache/shenyu/common/constant/Constants.java | 5 +
3 files changed, 331 insertions(+), 139 deletions(-)
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java
new file mode 100644
index 000000000..fa0739351
--- /dev/null
+++
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java
@@ -0,0 +1,225 @@
+/*
+ * 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.client.core.client;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
+import
org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
+import
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
+import org.apache.shenyu.common.utils.UriUtils;
+import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
+import org.apache.shenyu.register.common.config.PropertiesConfig;
+import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
+import org.apache.shenyu.register.common.dto.URIRegisterDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.aop.support.AopUtils;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.core.annotation.AnnotatedElementUtils;
+import org.springframework.lang.NonNull;
+import org.springframework.lang.Nullable;
+import org.springframework.util.ReflectionUtils;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * The type abstract context refreshed event listener.
+ *
+ * <p>See <a href="https://github.com/apache/shenyu/issues/415">upload dubbo
metadata on ContextRefreshedEvent</a>
+ */
+public abstract class AbstractContextRefreshedEventListener<T, A extends
Annotation> implements ApplicationListener<ContextRefreshedEvent> {
+
+ protected static final Logger LOG =
LoggerFactory.getLogger(AbstractContextRefreshedEventListener.class);
+
+ /**
+ * api path separator.
+ */
+ protected static final String PATH_SEPARATOR = "/";
+
+ private final ShenyuClientRegisterEventPublisher publisher =
ShenyuClientRegisterEventPublisher.getInstance();
+
+ private final AtomicBoolean registered = new AtomicBoolean(false);
+
+ private final String appName;
+
+ private final String contextPath;
+
+ private final String host;
+
+ private final String port;
+
+ /**
+ * Instantiates a new context refreshed event listener.
+ *
+ * @param clientConfig the shenyu client config
+ * @param shenyuClientRegisterRepository the shenyuClientRegisterRepository
+ */
+ public AbstractContextRefreshedEventListener(final PropertiesConfig
clientConfig,
+ final
ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
+ Properties props = clientConfig.getProps();
+ this.appName = props.getProperty(ShenyuClientConstants.APP_NAME);
+ this.contextPath =
Optional.ofNullable(props.getProperty(ShenyuClientConstants.CONTEXT_PATH)).map(UriUtils::repairData).orElse("");
+ if (StringUtils.isBlank(appName) && StringUtils.isBlank(contextPath)) {
+ String errorMsg = "client register param must config the appName
or contextPath";
+ LOG.error(errorMsg);
+ throw new ShenyuClientIllegalArgumentException(errorMsg);
+ }
+ this.host = props.getProperty(ShenyuClientConstants.HOST);
+ this.port = props.getProperty(ShenyuClientConstants.PORT);
+ publisher.start(shenyuClientRegisterRepository);
+ }
+
+ @Override
+ public void onApplicationEvent(@NonNull final ContextRefreshedEvent event)
{
+ if (!registered.compareAndSet(false, true)) {
+ return;
+ }
+ final ApplicationContext context = event.getApplicationContext();
+ Map<String, T> beans = getBeans(context);
+ if (beans.isEmpty()) {
+ return;
+ }
+ publisher.publishEvent(buildURIRegisterDTO(context, beans));
+ beans.forEach(this::handle);
+ }
+
+ protected abstract Map<String, T> getBeans(ApplicationContext context);
+
+ @SuppressWarnings("all")
+ protected abstract URIRegisterDTO buildURIRegisterDTO(ApplicationContext
context,
+ Map<String, T>
beans);
+
+ protected void handle(final String beanName, final T bean) {
+ Class<?> clazz = getCorrectedClass(bean);
+ final A beanShenyuClient =
AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType());
+ final String superPath = buildApiSuperPath(clazz, beanShenyuClient);
+ // Compatible with previous versions
+ if (Objects.nonNull(beanShenyuClient) && superPath.contains("*")) {
+ handleClass(clazz, bean, beanShenyuClient, superPath);
+ return;
+ }
+ final Method[] methods =
ReflectionUtils.getUniqueDeclaredMethods(clazz);
+ for (Method method : methods) {
+ handleMethod(bean, clazz, method, superPath);
+ }
+ }
+
+ protected Class<?> getCorrectedClass(final T bean) {
+ Class<?> clazz = bean.getClass();
+ if (AopUtils.isAopProxy(bean)) {
+ clazz = AopUtils.getTargetClass(bean);
+ }
+ return clazz;
+ }
+
+ protected abstract String buildApiSuperPath(Class<?> clazz,
+ @Nullable A beanShenyuClient);
+
+ protected void handleClass(final Class<?> clazz,
+ final T bean,
+ @NonNull final A beanShenyuClient,
+ final String superPath) {
+ publisher.publishEvent(buildMetaDataDTO(bean, beanShenyuClient,
pathJoin(contextPath, superPath), clazz, null));
+ }
+
+ protected void handleMethod(final T bean,
+ final Class<?> clazz,
+ final Method method,
+ final String superPath) {
+ A methodShenyuClient =
AnnotatedElementUtils.findMergedAnnotation(method, getAnnotationType());
+ if (Objects.nonNull(methodShenyuClient)) {
+ publisher.publishEvent(buildMetaDataDTO(bean, methodShenyuClient,
buildApiPath(method, superPath, methodShenyuClient), clazz, method));
+ }
+ }
+
+ protected abstract Class<A> getAnnotationType();
+
+ protected abstract String buildApiPath(Method method,
+ String superPath,
+ @NonNull A methodShenyuClient);
+
+ protected String pathJoin(@NonNull final String... path) {
+ StringBuilder result = new StringBuilder(PATH_SEPARATOR);
+ for (String p : path) {
+ if (!result.toString().endsWith(PATH_SEPARATOR)) {
+ result.append(PATH_SEPARATOR);
+ }
+ result.append(p.startsWith(PATH_SEPARATOR) ?
p.replaceFirst(PATH_SEPARATOR, "") : p);
+ }
+ return result.toString();
+ }
+
+ protected abstract MetaDataRegisterDTO buildMetaDataDTO(T bean,
+ @NonNull A
shenyuClient,
+ String path,
+ Class<?> clazz,
+ Method method);
+
+ /**
+ * Get the event publisher.
+ *
+ * @return the event publisher
+ */
+ public ShenyuClientRegisterEventPublisher getPublisher() {
+ return publisher;
+ }
+
+ /**
+ * Get the app name.
+ *
+ * @return the app name
+ */
+ public String getAppName() {
+ return appName;
+ }
+
+ /**
+ * Get the context path.
+ *
+ * @return the context path
+ */
+ public String getContextPath() {
+ return contextPath;
+ }
+
+ /**
+ * Get the host.
+ *
+ * @return the host
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * Get the port.
+ *
+ * @return the port
+ */
+ public String getPort() {
+ return port;
+ }
+}
diff --git
a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
index c251b65d5..8e2a25ea7 100644
---
a/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
+++
b/shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
@@ -20,13 +20,12 @@ package org.apache.shenyu.client.apache.dubbo;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.spring.ServiceBean;
-import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
-import
org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
-import
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
+import
org.apache.shenyu.client.core.client.AbstractContextRefreshedEventListener;
import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
import org.apache.shenyu.client.dubbo.common.dto.DubboRpcExt;
-import org.apache.shenyu.common.concurrent.ShenyuThreadFactory;
+import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.exception.ShenyuException;
import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.common.utils.IpUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
@@ -34,20 +33,16 @@ import
org.apache.shenyu.register.common.config.PropertiesConfig;
import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
import org.apache.shenyu.register.common.dto.URIRegisterDTO;
import org.springframework.aop.support.AopUtils;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.event.ContextRefreshedEvent;
-import org.springframework.core.annotation.AnnotatedElementUtils;
+import org.springframework.context.ApplicationContext;
import org.springframework.lang.NonNull;
+import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
-import java.util.Properties;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.Optional;
import java.util.stream.Collectors;
import static org.apache.dubbo.remoting.Constants.DEFAULT_CONNECT_TIMEOUT;
@@ -55,172 +50,139 @@ import static
org.apache.dubbo.remoting.Constants.DEFAULT_CONNECT_TIMEOUT;
/**
* The Apache Dubbo ServiceBean Listener.
*/
-@SuppressWarnings("all")
-public class ApacheDubboServiceBeanListener implements
ApplicationListener<ContextRefreshedEvent> {
-
- private static final String DEFAULT_CLUSTER = "failover";
-
- /**
- * api path separator.
- */
- private static final String PATH_SEPARATOR = "/";
-
- private static final Boolean DEFAULT_SENT = Boolean.FALSE;
-
- private ShenyuClientRegisterEventPublisher publisher =
ShenyuClientRegisterEventPublisher.getInstance();
-
- private final AtomicBoolean registered = new AtomicBoolean(false);
-
- private ExecutorService executorService;
-
- private String contextPath;
-
- private String appName;
-
- private final String host;
-
- private final String port;
-
- public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig,
final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
- Properties props = clientConfig.getProps();
- String contextPath =
props.getProperty(ShenyuClientConstants.CONTEXT_PATH);
- String appName = props.getProperty(ShenyuClientConstants.APP_NAME);
- if (StringUtils.isBlank(contextPath)) {
- throw new ShenyuClientIllegalArgumentException("apache dubbo
client must config the contextPath or appName");
- }
- this.contextPath = contextPath;
- this.appName = appName;
- this.host = props.getProperty(ShenyuClientConstants.HOST);
- this.port = props.getProperty(ShenyuClientConstants.PORT);
- executorService =
Executors.newSingleThreadExecutor(ShenyuThreadFactory.create("shenyu-apache-dubbo-client-thread-pool",
false));
- publisher.start(shenyuClientRegisterRepository);
- }
-
+public class ApacheDubboServiceBeanListener extends
AbstractContextRefreshedEventListener<ServiceBean, ShenyuDubboClient> {
+
/**
- * notes:When the "servicebean" is not obtained from the context, wait for
the subsequent contextrefreshedevent.
+ * Instantiates a new context refreshed event listener.
*
- * @param contextRefreshedEvent spring contextRefreshedEvent
+ * @param clientConfig the shenyu dubbo client config
+ * @param shenyuClientRegisterRepository the shenyuClientRegisterRepository
*/
+ public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig,
+ final ShenyuClientRegisterRepository
shenyuClientRegisterRepository) {
+ super(clientConfig, shenyuClientRegisterRepository);
+ }
+
@Override
- public void onApplicationEvent(final ContextRefreshedEvent
contextRefreshedEvent) {
- // Fix bug(https://github.com/apache/shenyu/issues/415), upload dubbo
metadata on ContextRefreshedEvent
- Map<String, ServiceBean> serviceBean =
contextRefreshedEvent.getApplicationContext().getBeansOfType(ServiceBean.class);
- if (serviceBean.isEmpty()) {
- return;
- }
- if (!registered.compareAndSet(false, true)) {
- return;
- }
- for (Map.Entry<String, ServiceBean> entry : serviceBean.entrySet()) {
- handler(entry.getValue());
- }
- serviceBean.values().stream().findFirst().ifPresent(bean -> {
- publisher.publishEvent(buildURIRegisterDTO(bean));
- });
+ protected Map<String, ServiceBean> getBeans(final ApplicationContext
context) {
+ return context.getBeansOfType(ServiceBean.class);
}
-
- private void handler(final ServiceBean<?> serviceBean) {
- Object refProxy = serviceBean.getRef();
+
+ @Override
+ protected Class<?> getCorrectedClass(final ServiceBean bean) {
+ Object refProxy = bean.getRef();
Class<?> clazz = refProxy.getClass();
if (AopUtils.isAopProxy(refProxy)) {
clazz = AopUtils.getTargetClass(refProxy);
}
- final ShenyuDubboClient beanShenyuClient =
AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuDubboClient.class);
- final String superPath = buildApiSuperPath(clazz, beanShenyuClient);
- if (superPath.contains("*") && Objects.nonNull(beanShenyuClient)) {
- Method[] methods = ReflectionUtils.getDeclaredMethods(clazz);
- for (Method method : methods) {
- publisher.publishEvent(buildMetaDataDTO(serviceBean,
beanShenyuClient, method, superPath));
- }
- return;
- }
- Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz);
- for (Method method : methods) {
- ShenyuDubboClient methodShenyuClient =
AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
- if (Objects.nonNull(methodShenyuClient)) {
- publisher.publishEvent(buildMetaDataDTO(serviceBean,
methodShenyuClient, method, superPath));
- }
- }
+ return clazz;
}
-
- private String buildApiSuperPath(@NonNull final Class<?> clazz, final
ShenyuDubboClient shenyuDubboClient) {
- if (Objects.nonNull(shenyuDubboClient) &&
!StringUtils.isBlank(shenyuDubboClient.path())) {
- return shenyuDubboClient.path();
+
+ @Override
+ protected URIRegisterDTO buildURIRegisterDTO(final ApplicationContext
context,
+ final Map<String,
ServiceBean> beans) {
+ return beans.entrySet().stream().findFirst().map(entry -> {
+ final ServiceBean<?> bean = entry.getValue();
+ return URIRegisterDTO.builder()
+ .contextPath(getContextPath())
+ .appName(buildAppName(bean))
+ .rpcType(RpcTypeEnum.DUBBO.getName())
+ .host(buildHost())
+ .port(buildPort(bean))
+ .build();
+ }).orElse(null);
+ }
+
+ private String buildAppName(final ServiceBean<?> serviceBean) {
+ String appName = this.getAppName();
+ return StringUtils.isBlank(appName) ?
serviceBean.getApplication().getName() : appName;
+ }
+
+ private String buildHost() {
+ final String host = this.getHost();
+ return IpUtils.isCompleteHost(host) ? host : IpUtils.getHost(host);
+ }
+
+ private int buildPort(final ServiceBean<?> serviceBean) {
+ final String port = this.getPort();
+ return StringUtils.isBlank(port) ? serviceBean.getProtocol().getPort()
: Integer.parseInt(port);
+ }
+
+ @Override
+ protected Class<ShenyuDubboClient> getAnnotationType() {
+ return ShenyuDubboClient.class;
+ }
+
+ @Override
+ protected String buildApiSuperPath(final Class<?> clazz,
+ @Nullable final ShenyuDubboClient
beanShenyuClient) {
+ if (Objects.nonNull(beanShenyuClient) &&
!StringUtils.isBlank(beanShenyuClient.path())) {
+ return beanShenyuClient.path();
}
return "";
}
-
- private String pathJoin(@NonNull final String... path) {
- StringBuilder result = new StringBuilder(PATH_SEPARATOR);
- for (String p : path) {
- if (!result.toString().endsWith(PATH_SEPARATOR)) {
- result.append(PATH_SEPARATOR);
- }
- result.append(p.startsWith(PATH_SEPARATOR) ?
p.replaceFirst(PATH_SEPARATOR, "") : p);
+
+ @Override
+ protected void handleClass(final Class<?> clazz,
+ final ServiceBean bean,
+ @NonNull final ShenyuDubboClient
beanShenyuClient,
+ final String superPath) {
+ Method[] methods = ReflectionUtils.getDeclaredMethods(clazz);
+ for (Method method : methods) {
+ getPublisher().publishEvent(buildMetaDataDTO(bean,
beanShenyuClient, pathJoin(getContextPath(), superPath), clazz, method));
}
- return result.toString();
}
-
- private MetaDataRegisterDTO buildMetaDataDTO(final ServiceBean<?>
serviceBean, final ShenyuDubboClient shenyuDubboClient, final Method method,
final String superPath) {
- String appName = buildAppName(serviceBean);
- String path = superPath.contains("*") ? pathJoin(contextPath,
superPath.replace("*", ""), method.getName()) : pathJoin(contextPath,
superPath, shenyuDubboClient.path());
- String desc = shenyuDubboClient.desc();
- String serviceName = serviceBean.getInterface();
- String configRuleName = shenyuDubboClient.ruleName();
+
+ @Override
+ protected String buildApiPath(final Method method,
+ final String superPath,
+ @NonNull final ShenyuDubboClient
methodShenyuClient) {
+ final String contextPath = this.getContextPath();
+ return superPath.contains("*") ? pathJoin(contextPath,
superPath.replace("*", ""), method.getName())
+ : pathJoin(contextPath, superPath, methodShenyuClient.path());
+ }
+
+ @Override
+ protected MetaDataRegisterDTO buildMetaDataDTO(final ServiceBean bean,
+ @NonNull final
ShenyuDubboClient shenyuClient,
+ final String path, final
Class<?> clazz,
+ final Method method) {
+ String appName = buildAppName(bean);
+ String desc = shenyuClient.desc();
+ String serviceName = bean.getInterface();
+ String configRuleName = shenyuClient.ruleName();
String ruleName = ("".equals(configRuleName)) ? path : configRuleName;
- String methodName = method.getName();
+ String methodName =
Optional.ofNullable(method).map(Method::getName).orElseThrow(() -> new
ShenyuException("unexpected error"));
Class<?>[] parameterTypesClazz = method.getParameterTypes();
String parameterTypes =
Arrays.stream(parameterTypesClazz).map(Class::getName).collect(Collectors.joining(","));
return MetaDataRegisterDTO.builder()
.appName(appName)
.serviceName(serviceName)
.methodName(methodName)
- .contextPath(contextPath)
+ .contextPath(getContextPath())
.host(buildHost())
- .port(buildPort(serviceBean))
+ .port(buildPort(bean))
.path(path)
.ruleName(ruleName)
.pathDesc(desc)
.parameterTypes(parameterTypes)
- .rpcExt(buildRpcExt(serviceBean))
+ .rpcExt(buildRpcExt(bean))
.rpcType(RpcTypeEnum.DUBBO.getName())
- .enabled(shenyuDubboClient.enabled())
+ .enabled(shenyuClient.enabled())
.build();
}
-
- private URIRegisterDTO buildURIRegisterDTO(final ServiceBean serviceBean) {
- return URIRegisterDTO.builder()
- .contextPath(this.contextPath)
- .appName(buildAppName(serviceBean))
- .rpcType(RpcTypeEnum.DUBBO.getName())
- .host(buildHost())
- .port(buildPort(serviceBean))
- .build();
- }
-
- private String buildRpcExt(final ServiceBean serviceBean) {
+
+ private String buildRpcExt(final ServiceBean<?> serviceBean) {
DubboRpcExt build = DubboRpcExt.builder()
.group(StringUtils.isNotEmpty(serviceBean.getGroup()) ?
serviceBean.getGroup() : "")
.version(StringUtils.isNotEmpty(serviceBean.getVersion()) ?
serviceBean.getVersion() : "")
.loadbalance(StringUtils.isNotEmpty(serviceBean.getLoadbalance()) ?
serviceBean.getLoadbalance() : CommonConstants.DEFAULT_LOADBALANCE)
.retries(Objects.isNull(serviceBean.getRetries()) ?
CommonConstants.DEFAULT_RETRIES : serviceBean.getRetries())
.timeout(Objects.isNull(serviceBean.getTimeout()) ?
DEFAULT_CONNECT_TIMEOUT : serviceBean.getTimeout())
- .sent(Objects.isNull(serviceBean.getSent()) ? DEFAULT_SENT :
serviceBean.getSent())
- .cluster(StringUtils.isNotEmpty(serviceBean.getCluster()) ?
serviceBean.getCluster() : DEFAULT_CLUSTER)
+ .sent(Objects.isNull(serviceBean.getSent()) ? Boolean.FALSE :
serviceBean.getSent())
+ .cluster(StringUtils.isNotEmpty(serviceBean.getCluster()) ?
serviceBean.getCluster() : Constants.DEFAULT_CLUSTER)
.url("")
.build();
return GsonUtils.getInstance().toJson(build);
}
-
- private String buildAppName(final ServiceBean serviceBean) {
- return StringUtils.isBlank(this.appName) ?
serviceBean.getApplication().getName() : this.appName;
- }
-
- private String buildHost() {
- return IpUtils.isCompleteHost(this.host) ? this.host :
IpUtils.getHost(this.host);
- }
-
- private int buildPort(final ServiceBean serviceBean) {
- return StringUtils.isBlank(this.port) ?
serviceBean.getProtocol().getPort() : Integer.parseInt(this.port);
- }
}
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
index ac106c868..75fc7cd65 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
@@ -631,6 +631,11 @@ public interface Constants {
* The maximum free memory reserved by the blocking queue for the JVM.
*/
int THE_256_MB = 256 * 1024 * 1024;
+
+ /**
+ * The default cluster of dubbo client.
+ */
+ String DEFAULT_CLUSTER = "failover";
/**
* String q.