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