dubbo文档优化
This commit is contained in:
@@ -54,7 +54,7 @@ public class DubboController {
|
||||
} else {
|
||||
providerList = this.getDubboInfoByZookeeper();
|
||||
}
|
||||
GenericService bean = ReferenceConfigHolder.getBean(providerList.get(0));
|
||||
GenericService bean = ReferenceConfigHolder.getBean(providerList.get(0).getNodeList().get(0));
|
||||
Object o = bean.$invoke("getUserList", new String[]{}, new String[]{});
|
||||
System.out.println(o);
|
||||
return DocResponseJson.ok(providerList);
|
||||
@@ -67,15 +67,19 @@ public class DubboController {
|
||||
String resultStr = HttpUtil.get(nacosUrl + "/v1/ns/instance/list?serviceName=" + service);
|
||||
NacosDubboInfo dubboInstance = JSON.parseObject(resultStr, NacosDubboInfo.class);
|
||||
List<NacosDubboInfo.HostsBean> hosts = dubboInstance.getHosts();
|
||||
DubboInfo dubboInfo = new DubboInfo();
|
||||
List<DubboInfo.DubboNodeInfo> nodeList = new LinkedList<>();
|
||||
for (NacosDubboInfo.HostsBean host : hosts) {
|
||||
DubboInfo dubboInfo = new DubboInfo();
|
||||
dubboInfo.setIp(host.getIp());
|
||||
dubboInfo.setPort(host.getPort());
|
||||
dubboInfo.setInterfaceX(host.getMetadata().getInterfaceX());
|
||||
dubboInfo.setMethods(host.getMetadata().getMethods().split(","));
|
||||
dubboInfo.setApplication(host.getMetadata().getApplication());
|
||||
providerList.add(dubboInfo);
|
||||
DubboInfo.DubboNodeInfo dubboNodeInfo = new DubboInfo.DubboNodeInfo();
|
||||
dubboNodeInfo.setIp(host.getIp());
|
||||
dubboNodeInfo.setPort(host.getPort());
|
||||
dubboNodeInfo.setInterfaceX(host.getMetadata().getInterfaceX());
|
||||
dubboNodeInfo.setMethods(host.getMetadata().getMethods().split(","));
|
||||
dubboNodeInfo.setApplication(host.getMetadata().getApplication());
|
||||
}
|
||||
dubboInfo.setInterfaceX(service.substring(service.indexOf(":") + 1));
|
||||
dubboInfo.setNodeList(nodeList);
|
||||
providerList.add(dubboInfo);
|
||||
}
|
||||
return providerList;
|
||||
}
|
||||
@@ -91,7 +95,8 @@ public class DubboController {
|
||||
List<DubboInfo> providerList = new LinkedList<>();
|
||||
for (String dubboStr : dubboList) {
|
||||
List<String> providers = client.getChildren().forPath("/dubbo/" + dubboStr + "/providers");
|
||||
List<DubboInfo> dubboInfoList = providers.stream().map(val -> {
|
||||
|
||||
List<DubboInfo.DubboNodeInfo> nodeList = providers.stream().map(val -> {
|
||||
String tempStr = val;
|
||||
try {
|
||||
tempStr = URLDecoder.decode(val, "utf-8");
|
||||
@@ -110,15 +115,18 @@ public class DubboController {
|
||||
String[] split = param.split("=");
|
||||
paramMap.put(split[0], split[1]);
|
||||
}
|
||||
DubboInfo dubboInfo = new DubboInfo();
|
||||
dubboInfo.setIp(ipPortArr[0]);
|
||||
dubboInfo.setPort(NumberUtils.toInt(ipPortArr[1]));
|
||||
dubboInfo.setInterfaceX(paramMap.get("interface"));
|
||||
dubboInfo.setMethods(paramMap.get("methods").split(","));
|
||||
dubboInfo.setApplication(paramMap.get("application"));
|
||||
return dubboInfo;
|
||||
DubboInfo.DubboNodeInfo dubboNodeInfo = new DubboInfo.DubboNodeInfo();
|
||||
dubboNodeInfo.setIp(ipPortArr[0]);
|
||||
dubboNodeInfo.setPort(NumberUtils.toInt(ipPortArr[1]));
|
||||
dubboNodeInfo.setInterfaceX(paramMap.get("interface"));
|
||||
dubboNodeInfo.setMethods(paramMap.get("methods").split(","));
|
||||
dubboNodeInfo.setApplication(paramMap.get("application"));
|
||||
return dubboNodeInfo;
|
||||
}).collect(Collectors.toList());
|
||||
providerList.addAll(dubboInfoList);
|
||||
DubboInfo dubboInfo = new DubboInfo();
|
||||
dubboInfo.setInterfaceX(dubboStr);
|
||||
dubboInfo.setNodeList(nodeList);
|
||||
providerList.add(dubboInfo);
|
||||
}
|
||||
return providerList;
|
||||
}
|
||||
|
||||
@@ -2,32 +2,72 @@ package com.zyplayer.doc.dubbo.framework.bean;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年1月10日
|
||||
**/
|
||||
public class DubboInfo {
|
||||
private Integer port;
|
||||
private String ip;
|
||||
@JSONField(name = "interface")
|
||||
private String interfaceX;
|
||||
private String[] methods;
|
||||
private String application;
|
||||
private List<DubboNodeInfo> nodeList;
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
public static class DubboNodeInfo {
|
||||
private Integer port;
|
||||
private String ip;
|
||||
@JSONField(name = "interface")
|
||||
private String interfaceX;
|
||||
private String[] methods;
|
||||
private String application;
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getInterfaceX() {
|
||||
return interfaceX;
|
||||
}
|
||||
|
||||
public void setInterfaceX(String interfaceX) {
|
||||
this.interfaceX = interfaceX;
|
||||
}
|
||||
|
||||
public String[] getMethods() {
|
||||
return methods;
|
||||
}
|
||||
|
||||
public void setMethods(String[] methods) {
|
||||
this.methods = methods;
|
||||
}
|
||||
|
||||
public String getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(String application) {
|
||||
this.application = application;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
public List<DubboNodeInfo> getNodeList() {
|
||||
return nodeList;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
public void setNodeList(List<DubboNodeInfo> nodeList) {
|
||||
this.nodeList = nodeList;
|
||||
}
|
||||
|
||||
public String getInterfaceX() {
|
||||
@@ -38,19 +78,4 @@ public class DubboInfo {
|
||||
this.interfaceX = interfaceX;
|
||||
}
|
||||
|
||||
public String[] getMethods() {
|
||||
return methods;
|
||||
}
|
||||
|
||||
public void setMethods(String[] methods) {
|
||||
this.methods = methods;
|
||||
}
|
||||
|
||||
public String getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(String application) {
|
||||
this.application = application;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class ReferenceConfigHolder {
|
||||
private static Map<String, ReferenceConfig> referenceConfigMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static GenericService getBean(DubboInfo dubboInfo) {
|
||||
String name = dubboInfo.getInterfaceX();
|
||||
String url = "dubbo://" + dubboInfo.getIp() + ":" + dubboInfo.getPort() + "/" + dubboInfo.getInterfaceX();
|
||||
ReferenceConfig referenceConfig = referenceConfigMap.get(name);
|
||||
public static GenericService getBean(DubboInfo.DubboNodeInfo dubboNodeInfo) {
|
||||
String name = dubboNodeInfo.getInterfaceX();
|
||||
String url = "dubbo://" + dubboNodeInfo.getIp() + ":" + dubboNodeInfo.getPort() + "/" + dubboNodeInfo.getInterfaceX();
|
||||
ReferenceConfig referenceConfig = referenceConfigMap.get(url);
|
||||
if (referenceConfig == null) {
|
||||
ApplicationConfig application = new ApplicationConfig();
|
||||
application.setName("zyplayer-doc-consume");
|
||||
@@ -31,7 +31,7 @@ public class ReferenceConfigHolder {
|
||||
referenceConfig.setInterface(name.substring(name.lastIndexOf(".") + 1));
|
||||
referenceConfig.setGeneric(true);
|
||||
referenceConfig.setApplication(application);
|
||||
referenceConfigMap.put(name, referenceConfig);
|
||||
referenceConfigMap.put(url, referenceConfig);
|
||||
}
|
||||
return (GenericService) referenceConfig.get();
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ zyplayer:
|
||||
doc:
|
||||
# dubbo相关配置
|
||||
dubbo:
|
||||
# zookeeper:
|
||||
# url: 127.0.0.1:2181
|
||||
nacos:
|
||||
url: http://127.0.0.1:8848/nacos
|
||||
# 优先使用zookeeper,未配置时找nacos的配置
|
||||
zookeeper:
|
||||
url: 127.0.0.1:2181
|
||||
# nacos:
|
||||
# url: http://127.0.0.1:8848/nacos
|
||||
# 服务名称,多个使用 ; 分割
|
||||
service: providers:com.zyplayer.dubbo.service.UserService;providers:com.zyplayer.dubbo.service.AnnotateService;
|
||||
# swagger相关配置
|
||||
|
||||
Reference in New Issue
Block a user