Skip to content

Commit

Permalink
Merge branch 'master' into dev-shenyu-kubernetes-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Aias00 authored Jan 14, 2025
2 parents 67b95b3 + 1d05819 commit 25c493e
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -201,7 +202,7 @@ protected MetaDataRegisterDTO buildMetaDataDTO(final ServiceBean bean,
.ruleName(ruleName)
.pathDesc(desc)
.parameterTypes(parameterTypes)
.rpcExt(buildRpcExt(bean))
.rpcExt(buildRpcExt(bean, methodName))
.rpcType(RpcTypeEnum.DUBBO.getName())
.enabled(shenyuClient.enabled())
.namespaceId(namespaceId)
Expand All @@ -219,7 +220,7 @@ public String getPort() {
}).orElse(port);
}

private String buildRpcExt(final ServiceBean<?> serviceBean) {
private String buildRpcExt(final ServiceBean<?> serviceBean, final String methodName) {
DubboRpcExt build = DubboRpcExt.builder()
.protocol(StringUtils.isNotEmpty(serviceBean.getProtocol().getName()) ? serviceBean.getProtocol().getName() : "")
.group(StringUtils.isNotEmpty(serviceBean.getGroup()) ? serviceBean.getGroup() : "")
Expand All @@ -231,6 +232,16 @@ private String buildRpcExt(final ServiceBean<?> serviceBean) {
.cluster(StringUtils.isNotEmpty(serviceBean.getCluster()) ? serviceBean.getCluster() : Constants.DEFAULT_CLUSTER)
.url("")
.build();
// set method config: loadbalance,retries,timeout,sent
Optional.ofNullable(serviceBean.getMethods()).orElse(Collections.emptyList()).stream()
.filter(m -> methodName.equals(m.getName()))
.findFirst()
.ifPresent(methodConfig -> {
Optional.ofNullable(methodConfig.getLoadbalance()).filter(StringUtils::isNotEmpty).ifPresent(build::setLoadbalance);
Optional.ofNullable(methodConfig.getRetries()).ifPresent(build::setRetries);
Optional.ofNullable(methodConfig.getTimeout()).ifPresent(build::setTimeout);
Optional.ofNullable(methodConfig.getSent()).ifPresent(build::setSent);
});
return GsonUtils.getInstance().toJson(build);
}
}

0 comments on commit 25c493e

Please sign in to comment.