增加dubbo接口文档
This commit is contained in:
3
pom.xml
3
pom.xml
@@ -48,5 +48,6 @@
|
|||||||
<module>zyplayer-doc-manage</module>
|
<module>zyplayer-doc-manage</module>
|
||||||
<module>zyplayer-doc-swagger</module>
|
<module>zyplayer-doc-swagger</module>
|
||||||
<module>zyplayer-doc-core</module>
|
<module>zyplayer-doc-core</module>
|
||||||
|
<module>zyplayer-doc-dubbo</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
279
zyplayer-doc-dubbo/pom.xml
Normal file
279
zyplayer-doc-dubbo/pom.xml
Normal file
@@ -0,0 +1,279 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.zyplayer</groupId>
|
||||||
|
<artifactId>zyplayer-doc-dubbo</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>zyplayer-doc-dubbo</name>
|
||||||
|
|
||||||
|
<description>dubbo文档工具</description>
|
||||||
|
<url>https://gitee.com/zyplayer/zyplayer-doc/zyplayer-doc-dubbo</url>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>zyplayer</id>
|
||||||
|
<name>暮光:城中城</name>
|
||||||
|
<email>806783409@qq.com</email>
|
||||||
|
<roles>
|
||||||
|
<role>Java Development Engineer</role>
|
||||||
|
</roles>
|
||||||
|
<timezone>2018-05-22 16:06:06</timezone>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>1.4.2.RELEASE</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<!-- 打包跳过单元测试 -->
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
<destDir>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${project.version}</destDir>
|
||||||
|
<zyplayer.doc.core.version>1.0.0</zyplayer.doc.core.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jta-atomikos</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis</artifactId>
|
||||||
|
<version>3.4.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis-spring</artifactId>
|
||||||
|
<version>1.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
|
<version>2.7.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.44</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-http</artifactId>
|
||||||
|
<version>4.1.8</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.curator</groupId>
|
||||||
|
<artifactId>curator-recipes</artifactId>
|
||||||
|
<version>2.12.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zyplayer</groupId>
|
||||||
|
<artifactId>zyplayer-doc-core</artifactId>
|
||||||
|
<version>${zyplayer.doc.core.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.boot</groupId>
|
||||||
|
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||||
|
<version>0.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.boot</groupId>
|
||||||
|
<artifactId>dubbo-spring-boot-actuator</artifactId>
|
||||||
|
<version>0.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.boot</groupId>
|
||||||
|
<artifactId>nacos-config-spring-boot-starter</artifactId>
|
||||||
|
<version>0.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Dubbo Nacos registry dependency -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>dubbo-registry-nacos</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Dubbo dependency -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>dubbo</artifactId>
|
||||||
|
<version>2.6.5</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Alibaba Spring Context extension -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.spring</groupId>
|
||||||
|
<artifactId>spring-context-support</artifactId>
|
||||||
|
<version>1.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>The Apache Software License, Version 2.0</name>
|
||||||
|
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git@git.oschina.net:zyplayer/zyplayer-doc.git</connection>
|
||||||
|
<developerConnection>scm:git@git.oschina.net:zyplayer/zyplayer-doc.git</developerConnection>
|
||||||
|
<url>git@git.oschina.net:zyplayer/zyplayer-doc.git</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
<repository>
|
||||||
|
<id>snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<targetPath>META-INF/resources/</targetPath>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/java</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/webapp</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>2.10.2</version>
|
||||||
|
<configuration>
|
||||||
|
<aggregate>true</aggregate>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-javadocs</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.18.1</version>
|
||||||
|
<configuration>
|
||||||
|
<skipTests>${skipTests}</skipTests>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>release</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>2.10.2</version>
|
||||||
|
<configuration>
|
||||||
|
<aggregate>true</aggregate>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-javadocs</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
|
<version>1.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>sign</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package com.zyplayer.doc.dubbo.controller;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.alibaba.dubbo.rpc.service.GenericService;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||||
|
import com.zyplayer.doc.dubbo.framework.bean.DubboInfo;
|
||||||
|
import com.zyplayer.doc.dubbo.framework.bean.NacosDubboInfo;
|
||||||
|
import com.zyplayer.doc.dubbo.framework.bean.ReferenceConfigHolder;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
|
import org.apache.curator.RetryPolicy;
|
||||||
|
import org.apache.curator.framework.CuratorFramework;
|
||||||
|
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||||
|
import org.apache.curator.retry.ExponentialBackoffRetry;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文档控制器
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2018年8月8日
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/zyplayer-doc-dubbo/doc-dubbo")
|
||||||
|
public class DubboController {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(DubboController.class);
|
||||||
|
|
||||||
|
@Value("${zyplayer.doc.dubbo.zookeeper.url:}")
|
||||||
|
private String zookeeperUrl;
|
||||||
|
@Value("${zyplayer.doc.dubbo.nacos.url:}")
|
||||||
|
private String nacosUrl;
|
||||||
|
@Value("${zyplayer.doc.dubbo.nacos.service:}")
|
||||||
|
private String nacosService;
|
||||||
|
|
||||||
|
@GetMapping(value = "/getList")
|
||||||
|
public DocResponseJson getDataSourceList() throws Exception {
|
||||||
|
List<DubboInfo> providerList;
|
||||||
|
if (StringUtils.isBlank(zookeeperUrl)) {
|
||||||
|
if (StringUtils.isBlank(nacosUrl) || StringUtils.isBlank(nacosService)) {
|
||||||
|
return DocResponseJson.warn("zyplayer.doc.dubbo.zookeeper.url、zyplayer.doc.dubbo.nacos.url 参数均未配置");
|
||||||
|
}
|
||||||
|
logger.info("zookeeper参数未配置,使用nacos配置");
|
||||||
|
providerList = this.getDubboInfoByNacos();
|
||||||
|
} else {
|
||||||
|
providerList = this.getDubboInfoByZookeeper();
|
||||||
|
}
|
||||||
|
GenericService bean = ReferenceConfigHolder.getBean(providerList.get(0));
|
||||||
|
Object o = bean.$invoke("getUserList", new String[]{}, new String[]{});
|
||||||
|
System.out.println(o);
|
||||||
|
return DocResponseJson.ok(providerList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DubboInfo> getDubboInfoByNacos() {
|
||||||
|
List<DubboInfo> providerList = new LinkedList<>();
|
||||||
|
String[] nacosServiceArr = nacosService.split(";");
|
||||||
|
for (String service : nacosServiceArr) {
|
||||||
|
String resultStr = HttpUtil.get(nacosUrl + "/v1/ns/instance/list?serviceName=" + service);
|
||||||
|
NacosDubboInfo dubboInstance = JSON.parseObject(resultStr, NacosDubboInfo.class);
|
||||||
|
List<NacosDubboInfo.HostsBean> hosts = dubboInstance.getHosts();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return providerList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DubboInfo> getDubboInfoByZookeeper() throws Exception {
|
||||||
|
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
|
||||||
|
CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
|
||||||
|
client.start();
|
||||||
|
List<String> dubboList = client.getChildren().forPath("/dubbo");
|
||||||
|
if (dubboList == null || dubboList.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
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 -> {
|
||||||
|
String tempStr = val;
|
||||||
|
try {
|
||||||
|
tempStr = URLDecoder.decode(val, "utf-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// IP和端口
|
||||||
|
String ipPort = tempStr.substring(tempStr.indexOf("://") + 3);
|
||||||
|
ipPort = ipPort.substring(0, ipPort.indexOf("/"));
|
||||||
|
String[] ipPortArr = ipPort.split(":");
|
||||||
|
// 参数
|
||||||
|
Map<String, String> paramMap = new HashMap<>();
|
||||||
|
String params = tempStr.substring(tempStr.indexOf("?"));
|
||||||
|
String[] paramsArr = params.split("&");
|
||||||
|
for (String param : paramsArr) {
|
||||||
|
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;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
providerList.addAll(dubboInfoList);
|
||||||
|
}
|
||||||
|
return providerList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.zyplayer.doc.dubbo.framework.bean;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,343 @@
|
|||||||
|
package com.zyplayer.doc.dubbo.framework.bean;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019年1月10日
|
||||||
|
**/
|
||||||
|
public class NacosDubboInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* metadata : {}
|
||||||
|
* dom : providers:com.zyplayer.dubbo.service.UserService
|
||||||
|
* cacheMillis : 10000
|
||||||
|
* useSpecifiedURL : false
|
||||||
|
* hosts : [{"valid":true,"marked":false,"metadata":{"side":"provider","protocol":"dubbo","application":"dubbo-provider","methods":"getUserDetail,getUserList","dubbo":"2.0.2","pid":"8164","interface":"com.zyplayer.dubbo.service.UserService","category":"providers","generic":"false","anyhost":"true","bean.name":"ServiceBean:com.zyplayer.dubbo.service.UserService","timestamp":"1549953970871"},"instanceId":"127.0.0.1#22223#DEFAULT#providers:com.zyplayer.dubbo.service.UserService","port":22223,"ip":"127.0.0.1","clusterName":"DEFAULT","weight":1,"serviceName":"providers:com.zyplayer.dubbo.service.UserService","enabled":true}]
|
||||||
|
* checksum : 2489ae2874f2f490caf7d6195192d6c71549954548862
|
||||||
|
* lastRefTime : 1549954548862
|
||||||
|
* env :
|
||||||
|
* clusters :
|
||||||
|
*/
|
||||||
|
|
||||||
|
private MetadataBean metadata;
|
||||||
|
private String dom;
|
||||||
|
private int cacheMillis;
|
||||||
|
private boolean useSpecifiedURL;
|
||||||
|
private String checksum;
|
||||||
|
private long lastRefTime;
|
||||||
|
private String env;
|
||||||
|
private String clusters;
|
||||||
|
private List<HostsBean> hosts;
|
||||||
|
|
||||||
|
public MetadataBean getMetadata() {
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadata(MetadataBean metadata) {
|
||||||
|
this.metadata = metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDom() {
|
||||||
|
return dom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDom(String dom) {
|
||||||
|
this.dom = dom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCacheMillis() {
|
||||||
|
return cacheMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCacheMillis(int cacheMillis) {
|
||||||
|
this.cacheMillis = cacheMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUseSpecifiedURL() {
|
||||||
|
return useSpecifiedURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseSpecifiedURL(boolean useSpecifiedURL) {
|
||||||
|
this.useSpecifiedURL = useSpecifiedURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChecksum() {
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChecksum(String checksum) {
|
||||||
|
this.checksum = checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastRefTime() {
|
||||||
|
return lastRefTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastRefTime(long lastRefTime) {
|
||||||
|
this.lastRefTime = lastRefTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEnv() {
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnv(String env) {
|
||||||
|
this.env = env;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClusters() {
|
||||||
|
return clusters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClusters(String clusters) {
|
||||||
|
this.clusters = clusters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HostsBean> getHosts() {
|
||||||
|
return hosts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHosts(List<HostsBean> hosts) {
|
||||||
|
this.hosts = hosts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MetadataBean {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HostsBean {
|
||||||
|
/**
|
||||||
|
* valid : true
|
||||||
|
* marked : false
|
||||||
|
* metadata : {"side":"provider","protocol":"dubbo","application":"dubbo-provider","methods":"getUserDetail,getUserList","dubbo":"2.0.2","pid":"8164","interface":"com.zyplayer.dubbo.service.UserService","category":"providers","generic":"false","anyhost":"true","bean.name":"ServiceBean:com.zyplayer.dubbo.service.UserService","timestamp":"1549953970871"}
|
||||||
|
* instanceId : 127.0.0.1#22223#DEFAULT#providers:com.zyplayer.dubbo.service.UserService
|
||||||
|
* port : 22223
|
||||||
|
* ip : 127.0.0.1
|
||||||
|
* clusterName : DEFAULT
|
||||||
|
* weight : 1
|
||||||
|
* serviceName : providers:com.zyplayer.dubbo.service.UserService
|
||||||
|
* enabled : true
|
||||||
|
*/
|
||||||
|
|
||||||
|
private boolean valid;
|
||||||
|
private boolean marked;
|
||||||
|
private MetadataBeanX metadata;
|
||||||
|
private String instanceId;
|
||||||
|
private int port;
|
||||||
|
private String ip;
|
||||||
|
private String clusterName;
|
||||||
|
private int weight;
|
||||||
|
private String serviceName;
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValid(boolean valid) {
|
||||||
|
this.valid = valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMarked() {
|
||||||
|
return marked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMarked(boolean marked) {
|
||||||
|
this.marked = marked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataBeanX getMetadata() {
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadata(MetadataBeanX metadata) {
|
||||||
|
this.metadata = metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInstanceId() {
|
||||||
|
return instanceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstanceId(String instanceId) {
|
||||||
|
this.instanceId = instanceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIp(String ip) {
|
||||||
|
this.ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClusterName() {
|
||||||
|
return clusterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClusterName(String clusterName) {
|
||||||
|
this.clusterName = clusterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeight(int weight) {
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServiceName() {
|
||||||
|
return serviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceName(String serviceName) {
|
||||||
|
this.serviceName = serviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MetadataBeanX {
|
||||||
|
/**
|
||||||
|
* side : provider
|
||||||
|
* protocol : dubbo
|
||||||
|
* application : dubbo-provider
|
||||||
|
* methods : getUserDetail,getUserList
|
||||||
|
* dubbo : 2.0.2
|
||||||
|
* pid : 8164
|
||||||
|
* interface : com.zyplayer.dubbo.service.UserService
|
||||||
|
* category : providers
|
||||||
|
* generic : false
|
||||||
|
* anyhost : true
|
||||||
|
* bean.name : ServiceBean:com.zyplayer.dubbo.service.UserService
|
||||||
|
* timestamp : 1549953970871
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String side;
|
||||||
|
private String protocol;
|
||||||
|
private String application;
|
||||||
|
private String methods;
|
||||||
|
private String dubbo;
|
||||||
|
private String pid;
|
||||||
|
@JSONField(name = "interface")
|
||||||
|
private String interfaceX;
|
||||||
|
private String category;
|
||||||
|
private String generic;
|
||||||
|
private String anyhost;
|
||||||
|
@JSONField(name = "bean.name")
|
||||||
|
private String _$BeanName0; // FIXME check this code
|
||||||
|
private String timestamp;
|
||||||
|
|
||||||
|
public String getSide() {
|
||||||
|
return side;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSide(String side) {
|
||||||
|
this.side = side;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProtocol() {
|
||||||
|
return protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProtocol(String protocol) {
|
||||||
|
this.protocol = protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApplication() {
|
||||||
|
return application;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplication(String application) {
|
||||||
|
this.application = application;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethods() {
|
||||||
|
return methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMethods(String methods) {
|
||||||
|
this.methods = methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDubbo() {
|
||||||
|
return dubbo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDubbo(String dubbo) {
|
||||||
|
this.dubbo = dubbo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPid() {
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPid(String pid) {
|
||||||
|
this.pid = pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInterfaceX() {
|
||||||
|
return interfaceX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInterfaceX(String interfaceX) {
|
||||||
|
this.interfaceX = interfaceX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(String category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGeneric() {
|
||||||
|
return generic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGeneric(String generic) {
|
||||||
|
this.generic = generic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAnyhost() {
|
||||||
|
return anyhost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAnyhost(String anyhost) {
|
||||||
|
this.anyhost = anyhost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get_$BeanName0() {
|
||||||
|
return _$BeanName0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set_$BeanName0(String _$BeanName0) {
|
||||||
|
this._$BeanName0 = _$BeanName0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimestamp(String timestamp) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.zyplayer.doc.dubbo.framework.bean;
|
||||||
|
|
||||||
|
import com.alibaba.dubbo.config.ApplicationConfig;
|
||||||
|
import com.alibaba.dubbo.config.ReferenceConfig;
|
||||||
|
import com.alibaba.dubbo.rpc.service.GenericService;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019年1月10日
|
||||||
|
**/
|
||||||
|
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);
|
||||||
|
if (referenceConfig == null) {
|
||||||
|
ApplicationConfig application = new ApplicationConfig();
|
||||||
|
application.setName("zyplayer-doc-consume");
|
||||||
|
// 参考:http://dubbo.apache.org/zh-cn/docs/user/configuration/api.html
|
||||||
|
// 此实例很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏
|
||||||
|
referenceConfig = new ReferenceConfig<>();
|
||||||
|
// 如果点对点直连,可以用reference.setUrl()指定目标地址,设置url后将绕过注册中心,
|
||||||
|
// 其中,协议对应provider.setProtocol()的值,端口对应provider.setPort()的值,
|
||||||
|
// 路径对应service.setPath()的值,如果未设置path,缺省path为接口名
|
||||||
|
referenceConfig.setUrl(url);
|
||||||
|
referenceConfig.setInterface(name.substring(name.lastIndexOf(".") + 1));
|
||||||
|
referenceConfig.setGeneric(true);
|
||||||
|
referenceConfig.setApplication(application);
|
||||||
|
referenceConfigMap.put(name, referenceConfig);
|
||||||
|
}
|
||||||
|
return (GenericService) referenceConfig.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.zyplayer.doc.dubbo.framework.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||||
|
@Target(value = { java.lang.annotation.ElementType.TYPE })
|
||||||
|
@Documented
|
||||||
|
@ComponentScan(basePackages = {
|
||||||
|
"com.zyplayer.doc.dubbo",
|
||||||
|
})
|
||||||
|
public @interface EnableDocDubbo {
|
||||||
|
}
|
||||||
57
zyplayer-doc-dubbo/src/main/resources/demo.txt
Normal file
57
zyplayer-doc-dubbo/src/main/resources/demo.txt
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
zookeeper 格式:
|
||||||
|
路劲:ls /dubbo/com.zyplayer.dubbo.service.UserService/providers
|
||||||
|
格式:
|
||||||
|
dubbo://127.0.0.1:22223/com.zyplayer.dubbo.service.UserService
|
||||||
|
?anyhost=true
|
||||||
|
&application=dubbo-provider
|
||||||
|
&bean.name=ServiceBean:com.zyplayer.dubbo.service.UserService
|
||||||
|
&dubbo=2.0.2
|
||||||
|
&generic=false
|
||||||
|
&interface=com.zyplayer.dubbo.service.UserService
|
||||||
|
&methods=getUserDetail,getUserList
|
||||||
|
&pid=36580
|
||||||
|
&side=provider
|
||||||
|
×tamp=1549955979708
|
||||||
|
|
||||||
|
nacos 格式:
|
||||||
|
文档:https://nacos.io/zh-cn/docs/open-API.html
|
||||||
|
请求地址:http://127.0.0.1:8848/nacos/v1/ns/instance/list?serviceName=providers:com.zyplayer.dubbo.service.UserService
|
||||||
|
格式:
|
||||||
|
{
|
||||||
|
"metadata": {},
|
||||||
|
"dom": "providers:com.zyplayer.dubbo.service.UserService",
|
||||||
|
"cacheMillis": 10000,
|
||||||
|
"useSpecifiedURL": false,
|
||||||
|
"hosts": [{
|
||||||
|
"valid": true,
|
||||||
|
"marked": false,
|
||||||
|
"metadata": {
|
||||||
|
"side": "provider",
|
||||||
|
"protocol": "dubbo",
|
||||||
|
"application": "dubbo-provider",
|
||||||
|
"methods": "getUserDetail,getUserList",
|
||||||
|
"dubbo": "2.0.2",
|
||||||
|
"pid": "8164",
|
||||||
|
"interface": "com.zyplayer.dubbo.service.UserService",
|
||||||
|
"category": "providers",
|
||||||
|
"generic": "false",
|
||||||
|
"anyhost": "true",
|
||||||
|
"bean.name": "ServiceBean:com.zyplayer.dubbo.service.UserService",
|
||||||
|
"timestamp": "1549953970871"
|
||||||
|
},
|
||||||
|
"instanceId": "127.0.0.1#22223#DEFAULT#providers:com.zyplayer.dubbo.service.UserService",
|
||||||
|
"port": 22223,
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"clusterName": "DEFAULT",
|
||||||
|
"weight": 1.0,
|
||||||
|
"serviceName": "providers:com.zyplayer.dubbo.service.UserService",
|
||||||
|
"enabled": true
|
||||||
|
}],
|
||||||
|
"checksum": "2489ae2874f2f490caf7d6195192d6c71549955797122",
|
||||||
|
"lastRefTime": 1549955797122,
|
||||||
|
"env": "",
|
||||||
|
"clusters": ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
<springfox.swagger.ui.version>2.9.2</springfox.swagger.ui.version>
|
<springfox.swagger.ui.version>2.9.2</springfox.swagger.ui.version>
|
||||||
<springfox.swagger.version>2.9.2</springfox.swagger.version>
|
<springfox.swagger.version>2.9.2</springfox.swagger.version>
|
||||||
<zyplayer.doc.db.version>1.0.1</zyplayer.doc.db.version>
|
<zyplayer.doc.db.version>1.0.1</zyplayer.doc.db.version>
|
||||||
|
<zyplayer.doc.dubbo.version>1.0.1</zyplayer.doc.dubbo.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -94,6 +95,12 @@
|
|||||||
<artifactId>zyplayer-doc-db</artifactId>
|
<artifactId>zyplayer-doc-db</artifactId>
|
||||||
<version>${zyplayer.doc.db.version}</version>
|
<version>${zyplayer.doc.db.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--zyplayer-doc-dubbo-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zyplayer</groupId>
|
||||||
|
<artifactId>zyplayer-doc-dubbo</artifactId>
|
||||||
|
<version>${zyplayer.doc.dubbo.version}</version>
|
||||||
|
</dependency>
|
||||||
<!--zyplayer-doc-swagger-->
|
<!--zyplayer-doc-swagger-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zyplayer</groupId>
|
<groupId>com.zyplayer</groupId>
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.zyplayer.doc.manage.framework.config;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.dubbo.framework.config.EnableDocDubbo;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author
|
||||||
|
* @Date 2018/11/11
|
||||||
|
**/
|
||||||
|
@EnableDocDubbo
|
||||||
|
@Configuration
|
||||||
|
public class DocDubboConfig {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,6 +11,15 @@ server:
|
|||||||
|
|
||||||
zyplayer:
|
zyplayer:
|
||||||
doc:
|
doc:
|
||||||
|
# dubbo相关配置
|
||||||
|
dubbo:
|
||||||
|
# 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相关配置
|
||||||
swagger:
|
swagger:
|
||||||
proxy-request:
|
proxy-request:
|
||||||
# 允许代理请求的域名,正则表达式,多个使用 ; 分割,必须设置,防止通过代理接口访问到内部资源,实在觉得没必要可设置为:.+
|
# 允许代理请求的域名,正则表达式,多个使用 ; 分割,必须设置,防止通过代理接口访问到内部资源,实在觉得没必要可设置为:.+
|
||||||
|
|||||||
Reference in New Issue
Block a user