Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type:fix] support dubbo method configure #5891

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading