Commit 4f9a5652 by Nepxion

增加控制台模块

parent 4d2935e2
<?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">
<groupId>com.nepxion</groupId>
<artifactId>discovery-console-example</artifactId>
<name>Nepxion Discovery Console Example</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<version>1.0.0</version>
<description>Nepxion Discovery is an enhancement for Spring Cloud Discovery</description>
<url>http://www.nepxion.com</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.14.RELEASE</version>
</parent>
<properties>
<discovery.plugin.version>3.3.9</discovery.plugin.version>
<spring.cloud.version>Edgware.SR4</spring.cloud.version>
<!-- <spring.cloud.version>Dalston.SR5</spring.cloud.version> -->
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-console-starter</artifactId>
<version>${discovery.plugin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<encoding>${project.build.sourceEncoding}</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.nepxion.discovery.console.example;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class DiscoveryConsoleApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(DiscoveryConsoleApplication.class).web(true).run(args);
}
}
\ No newline at end of file
# Spring cloud config
spring.application.name=discovery-console-example
server.port=2222
# Eureka config
eureka.client.serviceUrl.defaultZone=http://localhost:9528/eureka/
eureka.instance.preferIpAddress=true
# Consul config
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.preferIpAddress=true
# Zookeeper config
spring.cloud.zookeeper.connectString=localhost:2181
spring.cloud.zookeeper.discovery.root=/spring-cloud-service
spring.cloud.zookeeper.discovery.preferIpAddress=true
# Ribbon config
ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=60000
# Swagger config
swagger.service.base.package=com.nepxion.discovery.console.controller
swagger.service.description=Console Restful APIs
swagger.service.version=1.0.0
swagger.service.license=Apache License 2.0
swagger.service.license.url=http://www.apache.org/licenses/LICENSE-2.0
swagger.service.contact.name=Haojun Ren
swagger.service.contact.url=https://github.com/Nepxion/Discovery
swagger.service.contact.email=1394997@qq.com
\ No newline at end of file
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
<!-- Simple file output -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>discovery %date %level [%thread] %logger{10} [%file:%line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>log/discovery-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<!-- Safely log to the same file from multiple JVMs. Degrades performance! -->
<prudent>true</prudent>
</appender>
<appender name ="FILE_ASYNC" class= "ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>512</queueSize>
<appender-ref ref ="FILE"/>
</appender>
<!-- Console output -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>discovery %date %level [%thread] %logger{10} [%file:%line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<!-- Only log level WARN and above -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
</appender>
<!-- For loggers in the these namespaces, log at all levels. -->
<logger name="pedestal" level="ALL" />
<logger name="hammock-cafe" level="ALL" />
<logger name="user" level="ALL" />
<root level="INFO">
<!-- <appender-ref ref="FILE_ASYNC" /> -->
<appender-ref ref="STDOUT" />
</root>
</configuration>
<?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">
<artifactId>discovery-console-starter</artifactId>
<name>Nepxion Discovery Console Starter</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<description>Nepxion Discovery is an enhancement for Spring Cloud Discovery</description>
<url>http://www.nepxion.com</url>
<parent>
<groupId>com.nepxion</groupId>
<artifactId>discovery</artifactId>
<version>3.3.9</version>
</parent>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>discovery-console</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.nepxion.discovery.console.configuration.ConsoleAutoConfiguration
\ No newline at end of file
<?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">
<artifactId>discovery-console</artifactId>
<name>Nepxion Discovery Console</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<description>Nepxion Discovery is an enhancement for Spring Cloud Discovery</description>
<url>http://www.nepxion.com</url>
<parent>
<groupId>com.nepxion</groupId>
<artifactId>discovery</artifactId>
<version>3.3.9</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.nepxion.discovery.console.configuration;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import com.nepxion.discovery.console.controller.ConsoleController;
@Configuration
@Import(SwaggerConfiguration.class)
public class ConsoleAutoConfiguration {
@Bean
public ConsoleController consoleController() {
return new ConsoleController();
}
}
\ No newline at end of file
package com.nepxion.discovery.console.configuration;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfiguration extends WebMvcConfigurerAdapter {
@Value("${spring.application.name}")
private String serviceName;
@Value("${swagger.service.base.package}")
private String basePackage;
@Value("${swagger.service.description}")
private String description;
@Value("${swagger.service.version}")
private String version;
@Value("${swagger.service.license}")
private String license;
@Value("${swagger.service.license.url}")
private String licenseUrl;
@Value("${swagger.service.contact.name}")
private String contactName;
@Value("${swagger.service.contact.url}")
private String contactUrl;
@Value("${swagger.service.contact.email}")
private String contactEmail;
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage(basePackage)) // 扫描该包下的所有需要在Swagger中展示的API,@ApiIgnore注解标注的除外
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(serviceName)
.description(description)
.version(version)
.license(license)
.licenseUrl(licenseUrl)
.contact(new Contact(contactName, contactUrl, contactEmail))
.build();
}
// 解决跨域问题
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedHeaders("*")
.allowedMethods("*")
.allowedOrigins("*");
}
}
\ No newline at end of file
package com.nepxion.discovery.console.controller;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Api(tags = { "控制台接口" })
public class ConsoleController {
@Autowired
private DiscoveryClient discoveryClient;
@RequestMapping(path = "/services", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心所有服务列表", notes = "", response = List.class, httpMethod = "GET")
public List<String> services() {
return getServices();
}
@RequestMapping(path = "/instances/{serviceId}", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心服务的实例列表", notes = "", response = List.class, httpMethod = "GET")
public List<ServiceInstance> instances(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId) {
return getInstanceList(serviceId);
}
public List<String> getServices() {
return discoveryClient.getServices();
}
public List<ServiceInstance> getInstanceList(String serviceId) {
return discoveryClient.getInstances(serviceId);
}
}
\ No newline at end of file
...@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.routercenter.configuration; ...@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.routercenter.configuration;
*/ */
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -18,7 +17,6 @@ import org.springframework.web.client.RestTemplate; ...@@ -18,7 +17,6 @@ import org.springframework.web.client.RestTemplate;
import com.nepxion.discovery.plugin.routercenter.controller.RouterController; import com.nepxion.discovery.plugin.routercenter.controller.RouterController;
@Configuration @Configuration
@ComponentScan(basePackages = { "com.nepxion.discovery.plugin.routercenter.controller" })
@Import(SwaggerConfiguration.class) @Import(SwaggerConfiguration.class)
public class RouterAutoConfiguration { public class RouterAutoConfiguration {
@Bean @Bean
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
</parent> </parent>
<properties> <properties>
<discovery.plugin.version>3.3.9</discovery.plugin.version>
<spring.cloud.version>Edgware.SR4</spring.cloud.version> <spring.cloud.version>Edgware.SR4</spring.cloud.version>
<!-- <spring.cloud.version>Dalston.SR5</spring.cloud.version> --> <!-- <spring.cloud.version>Dalston.SR5</spring.cloud.version> -->
<discovery.plugin.version>3.3.9</discovery.plugin.version>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
......
...@@ -18,9 +18,12 @@ ...@@ -18,9 +18,12 @@
<module>discovery-plugin-config-center</module> <module>discovery-plugin-config-center</module>
<module>discovery-plugin-admin-center</module> <module>discovery-plugin-admin-center</module>
<module>discovery-plugin-router-center</module> <module>discovery-plugin-router-center</module>
<module>discovery-console</module>
<module>discovery-plugin-starter-eureka</module> <module>discovery-plugin-starter-eureka</module>
<module>discovery-plugin-starter-consul</module> <module>discovery-plugin-starter-consul</module>
<module>discovery-plugin-starter-zookeeper</module> <module>discovery-plugin-starter-zookeeper</module>
<module>discovery-console-starter</module>
<module>discovery-console-example</module>
<module>discovery-springcloud-example-eureka</module> <module>discovery-springcloud-example-eureka</module>
<module>discovery-springcloud-example</module> <module>discovery-springcloud-example</module>
</modules> </modules>
...@@ -90,6 +93,12 @@ ...@@ -90,6 +93,12 @@
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>discovery-console</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>discovery-plugin-starter-eureka</artifactId> <artifactId>discovery-plugin-starter-eureka</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
...@@ -108,6 +117,12 @@ ...@@ -108,6 +117,12 @@
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>discovery-console-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>eventbus-aop-starter</artifactId> <artifactId>eventbus-aop-starter</artifactId>
<version>${eventbus.version}</version> <version>${eventbus.version}</version>
</dependency> </dependency>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment