Commit 0d372751 by 仲光辉

蛋壳创意科技-技术测试-Discovery Initialization at 2020/10/12 10:48

parents
# Created by .ignore support plugin (hsz.mobi)
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
#IntelliJ IDEA
.idea
*.iml
log
# maven target
*/target
*/*/target
<?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">
<parent>
<artifactId>test-in-discovery</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>01-test-in-discovery-common</artifactId>
<dependencies>
<!-- 1.注册中心插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-register-center-starter-nacos</artifactId>
<version>${discovery.version}</version>
</dependency>
<!-- 2.配置中心插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-config-center-starter-nacos</artifactId>
<version>${discovery.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.test.common;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import org.springframework.stereotype.Component;
/**
* {@link Component}
* 公共工具类
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020-10-11
* @copyright www.dankal.cn
*/
@Component
public class CommonUtil {
/**
* PluginAdapter
*
* @see PluginAdapter
*/
private final PluginAdapter pluginAdapter;
public CommonUtil(PluginAdapter pluginAdapter) {
this.pluginAdapter = pluginAdapter;
}
/**
* 获取 当前微服务信息
*
* @param value 前置数据
* @return 拼接好数据前置数据的微服务信息
*/
public String getPluginInfo(String value) {
return pluginAdapter.getPluginInfo(value);
}
/**
* @param prefix 前置内容
* @param versionTag 包含版本信息 的 tag信息
* @return 拼接后的版本端点信息
*/
public String getSimpleTag(String prefix, String versionTag) {
return prefix + " -> [ operate by" + versionTag + " ]";
}
}
<?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">
<parent>
<artifactId>test-in-discovery</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>02-test-in-discovery-gateway</artifactId>
<dependencies>
<!-- 网关的策略编排插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-strategy-starter-gateway</artifactId>
<version>${discovery.version}</version>
</dependency>
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>01-test-in-discovery-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.test.common.gateway;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* {@link SpringBootApplication,EnableDiscoveryClient}
* SpringCloudGateway-Discovery 配置类
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/11
* @copyright www.dankal.cn
*/
@SpringBootApplication
@EnableDiscoveryClient
public class TestVersionGateway {
public static void main(String[] args) {
new SpringApplicationBuilder(TestVersionGateway.class).run(args);
}
}
\ No newline at end of file
# Spring cloud config
spring.application.name=test-service-gateway
server.port=5001
# Nacos config for discovery
spring.cloud.nacos.discovery.server-addr=register.mercymodest.com:58080
spring.cloud.nacos.discovery.metadata.group=test-service-group
spring.cloud.nacos.discovery.metadata.version=1.0
# spring.cloud.nacos.discovery.metadata.env=env1
# Nacos config for rule
nacos.server-addr=register.mercymodest.com:58080
# Nepxion discovery config
# 当外界传值Header的时候,网关也设置并传递同名的Header,需要决定哪个Header传递到后边的服务去。如果下面开关为true,以网关设置为优先,否则以外界传值为优先。缺失则默认为true
spring.application.strategy.gateway.header.priority=false
# 当以网关设置为优先的时候,网关未配置Header,而外界配置了Header,仍旧忽略外界的Header。缺失则默认为true
# spring.application.strategy.gateway.original.header.ignored=true
# Spring cloud gateway config
spring.cloud.discovery.reactive.enabled=false
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.discovery.locator.lowerCaseServiceId=true
\ 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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %logger{10} [%file:%line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>log/dankal-test-%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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %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>
\ 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">
<parent>
<artifactId>03-test-in-discovery-service</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>03-01-service-a</artifactId>
<dependencies>
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>01-test-in-discovery-common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.test.service;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* {@link EnableFeignClients,EnableDiscoveryClient,SpringBootApplication}
* Test Service A 启动类 V1
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/11
* @copyright www.dankal.cn
*/
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"cn.dankal.test"})
public class TestServiceAApplication2V1 {
public static void main(String[] args) {
new SpringApplicationBuilder(TestServiceAApplication2V1.class).run(args);
}
}
\ No newline at end of file
package cn.dankal.test.service.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* {@link FeignClient}
* Feign Client -> test-b Service
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020-10-11
* @copyright www.dankal.cn
*/
@FeignClient(value = "test-service-b")
public interface TestBClientV1 {
/**
* 远程调用 B 服务 V1.0.0
*
* @param value 服务信息
* @return 服务信息
* @since V1.0.0
*
*/
@GetMapping(path = "/test/info/{value}")
String info(@PathVariable(value = "value") String value);
/**
* 远程调用 B 服务 V1.0.0
*
* @param value 前置信息
* @return 版本标记信息
* @since V1.0.0
*/
@GetMapping(path = "/test/simple/{value}")
String simple(@PathVariable(value = "value") String value);
}
package cn.dankal.test.service.controller;
import cn.dankal.test.common.CommonUtil;
import cn.dankal.test.service.client.TestBClientV1;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* {@link RestController}
* TestAController
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020-10-11
* @copyright www.dankal.cn
*/
@RestController
public class TestAControllerV1 {
/**
* B Service Client V1
*/
private final TestBClientV1 bClientV1;
/**
* CommonUtil
*/
private final CommonUtil commonUtil;
public TestAControllerV1(TestBClientV1 bClientV1, CommonUtil commonUtil) {
this.bClientV1 = bClientV1;
this.commonUtil = commonUtil;
}
@GetMapping("/test/info/{value}")
public String info(@PathVariable(value = "value") String value) {
value = commonUtil.getPluginInfo(value);
return bClientV1.info(value);
}
@GetMapping("/test/simple/{value}")
public String simple(@PathVariable("value") String value) {
String versionTag = "service a V1";
value = commonUtil.getSimpleTag(value, versionTag);
return bClientV1.simple(value);
}
}
# Spring cloud config
server:
port: 3001
spring:
application:
name: test-service-a
# Nacos config for discovery
cloud:
nacos:
discovery:
metadata:
env: env1
group: test-service-group
region: dev
version: 1.0
zone: zone1
# Nacos config for discovery
spring.cloud.nacos.discovery.server-addr=register.mercymodest.com:58080
# Nacos config for rule
nacos.server-addr=register.mercymodest.com:58080
# Feign config
# 解决FeignClientSpecification的问题。支持G版或更高版本的配置,其它版本不需要该行配置
spring.main.allow-bean-definition-overriding=true
# Nepxion discovery config
# 路由策略的时候,需要指定对业务RestController类的扫描路径。此项配置作用于RPC方式的调用拦截、消费端的服务隔离和调用链三项功能
spring.application.strategy.scan.packages=com.nepxion.discovery.guide.service
\ 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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %logger{10} [%file:%line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>log/dankal-%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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %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>
\ 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">
<parent>
<artifactId>03-test-in-discovery-service</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>03-02-service-b</artifactId>
<dependencies>
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>01-test-in-discovery-common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.test.service;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* {@link EnableFeignClients,EnableDiscoveryClient,SpringBootApplication}
* Test Service B 启动类 V1
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/11
* @copyright www.dankal.cn
*/
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"cn.dankal.test"})
public class TestServiceBApplication2V1 {
public static void main(String[] args) {
new SpringApplicationBuilder(TestServiceBApplication2V1.class).run(args);
}
}
\ No newline at end of file
package cn.dankal.test.service.controller;
import cn.dankal.test.common.CommonUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* {@link RestController}
* TestBController V1
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020-10-11
* @copyright www.dankal.cn
* @since V1.0.0
*/
@RestController
public class TestBControllerV1 {
/**
* Common Util
*/
private final CommonUtil commonUtil;
public TestBControllerV1(CommonUtil commonUtil) {
this.commonUtil = commonUtil;
}
@GetMapping(path = "/test/info/{value}")
public String info(@PathVariable(value = "value") String value) {
return commonUtil.getPluginInfo(value);
}
@GetMapping(path = "/test/simple/{value}")
public String simple(@PathVariable(value = "value") String value) {
String versionTag = "service b V1";
return commonUtil.getSimpleTag(value, versionTag);
}
}
# Spring cloud config
server:
port: 4001
spring:
application:
name: test-service-b
# Nacos config for discovery
cloud:
nacos:
discovery:
metadata:
env: env1
group: test-service-group
region: dev
version: 1.0
zone: zone1
# Nacos config for discovery
spring.cloud.nacos.discovery.server-addr=register.mercymodest.com:58080
# Nacos config for rule
nacos.server-addr=register.mercymodest.com:58080
# Feign config
# 解决FeignClientSpecification的问题。支持G版或更高版本的配置,其它版本不需要该行配置
spring.main.allow-bean-definition-overriding=true
# Nepxion discovery config
# 路由策略的时候,需要指定对业务RestController类的扫描路径。此项配置作用于RPC方式的调用拦截、消费端的服务隔离和调用链三项功能
spring.application.strategy.scan.packages=com.nepxion.discovery.guide.service
\ 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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %logger{10} [%file:%line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>log/dankal-%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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %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>
\ 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">
<parent>
<artifactId>03-test-in-discovery-service</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>03-03-service-a2</artifactId>
<dependencies>
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>01-test-in-discovery-common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.test.service;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* {@link EnableDiscoveryClient,EnableFeignClients,SpringBootApplication}
* Test Service A 启动类 V2
*
* @author ZGH.MercyModest
* @version V2.0.0
* @create 2020/10/11
* @copyright www.dankal.cn
*/
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"cn.dankal.test"})
public class TestServiceAApplication2V2 {
public static void main(String[] args) {
new SpringApplicationBuilder(TestServiceAApplication2V2.class).run(args);
}
}
\ No newline at end of file
package cn.dankal.test.service.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* {@link FeignClient}
* TestBClient V2
*
* @author ZGH.MercyModest
* @version V2.0.0
* @create 2020-10-11
* @copyright www.dankal.cn
*/
@FeignClient(value = "test-service-b")
public interface TestBClientV2 {
/**
* 远程调用 B 服务
*
* @param value 服务信息
* @return 服务信息
* @since V2.0.0
*/
@GetMapping(path = "/test/info/{value}")
String info(@PathVariable(value = "value") String value);
/**
* 远程调用 B 服务
*
* @param value 前置信息
* @return 版本标记信息
* @since V2.0.0
*/
@GetMapping(path = "/test/simple/{value}")
String simple(@PathVariable(value = "value") String value);
}
package cn.dankal.test.service.controller;
import cn.dankal.test.common.CommonUtil;
import cn.dankal.test.service.client.TestBClientV2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* {@link RestController}
* TestAController V2
*
* @author ZGH.MercyModest
* @version V2.0.0
* @create 2020-10-11
* @copyright www.dankal.cn
*/
@RestController
public class TestAControllerV2 {
/**
* B Service Client V2
*/
private final TestBClientV2 bClientV2;
/**
* CommonUtil
*/
private final CommonUtil commonUtil;
public TestAControllerV2(TestBClientV2 bClientV2, CommonUtil commonUtil) {
this.bClientV2 = bClientV2;
this.commonUtil = commonUtil;
}
@GetMapping("/test/info/{value}")
public String info(@PathVariable(value = "value") String value) {
value = commonUtil.getPluginInfo(value);
return bClientV2.info(value);
}
@GetMapping("/test/simple/{value}")
public String simple(@PathVariable("value") String value) {
String versionTag = "service a V2";
value = commonUtil.getSimpleTag(value, versionTag);
return bClientV2.simple(value);
}
}
# Spring cloud config
server:
port: 3002
spring:
application:
name: test-service-a
# Nacos config for discovery
cloud:
nacos:
discovery:
metadata:
env: env2
group: test-service-group
region: dev
version: 2.0
zone: zone2
# Nacos config for discovery
spring.cloud.nacos.discovery.server-addr=register.mercymodest.com:58080
# Nacos config for rule
nacos.server-addr=register.mercymodest.com:58080
# Feign config
# 解决FeignClientSpecification的问题。支持G版或更高版本的配置,其它版本不需要该行配置
spring.main.allow-bean-definition-overriding=true
# Nepxion discovery config
# 路由策略的时候,需要指定对业务RestController类的扫描路径。此项配置作用于RPC方式的调用拦截、消费端的服务隔离和调用链三项功能
spring.application.strategy.scan.packages=com.nepxion.discovery.guide.service
\ 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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %logger{10} [%file:%line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>log/dankal-%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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %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>
\ 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">
<parent>
<artifactId>03-test-in-discovery-service</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>03-04-service-b2</artifactId>
<dependencies>
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>01-test-in-discovery-common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.test.service;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* {@link EnableFeignClients,EnableDiscoveryClient,SpringBootApplication}
* Test Service B 启动类 V2
*
* @author ZGH.MercyModest
* @version V2.0.0
* @create 2020/10/11
* @copyright www.dankal.cn
*/
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"cn.dankal.test"})
public class TestServiceBApplication2V2 {
public static void main(String[] args) {
new SpringApplicationBuilder(TestServiceBApplication2V2.class).run(args);
}
}
\ No newline at end of file
package cn.dankal.test.service.controller;
import cn.dankal.test.common.CommonUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* {@link RestController}
* TestBControllerV2
*
* @author ZGH.MercyModest
* @version V2.0.0
* @create 2020-10-11
* @copyright www.dankal.cn
*/
@RestController
public class TestBControllerV2 {
/**
* Common Util
*/
private final CommonUtil commonUtil;
public TestBControllerV2(CommonUtil commonUtil) {
this.commonUtil = commonUtil;
}
@GetMapping(path = "/test/info/{value}")
public String info(@PathVariable(value = "value") String value) {
return commonUtil.getPluginInfo(value);
}
@GetMapping(path = "/test/simple/{value}")
public String simple(@PathVariable(value = "value") String value) {
String versionTag = "service b V2";
return commonUtil.getSimpleTag(value, versionTag);
}
}
# Spring cloud config
server:
port: 4002
spring:
application:
name: test-service-b
# Nacos config for discovery
cloud:
nacos:
discovery:
metadata:
env: env2
group: test-service-group
region: dev
version: 2.0
zone: zone2
# Nacos config for discovery
spring.cloud.nacos.discovery.server-addr=register.mercymodest.com:58080
# Nacos config for rule
nacos.server-addr=register.mercymodest.com:58080
# Feign config
# 解决FeignClientSpecification的问题。支持G版或更高版本的配置,其它版本不需要该行配置
spring.main.allow-bean-definition-overriding=true
# Nepxion discovery config
# 路由策略的时候,需要指定对业务RestController类的扫描路径。此项配置作用于RPC方式的调用拦截、消费端的服务隔离和调用链三项功能
spring.application.strategy.scan.packages=com.nepxion.discovery.guide.service
\ 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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %logger{10} [%file:%line] - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>log/dankal-%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>cn.dankal.test %date %level [%thread] [%X{trace-id}] [%X{span-id}] [%X{n-d-service-group}] [%X{n-d-service-type}] [%X{n-d-service-app-id}] [%X{n-d-service-id}] [%X{n-d-service-address}] [%X{n-d-service-version}] [%X{n-d-service-region}] [%X{n-d-service-env}] [%X{n-d-service-zone}] [%X{mobile}] [%X{user}] %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>
\ 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">
<parent>
<artifactId>test-in-discovery</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>03-test-in-discovery-service</artifactId>
<packaging>pom</packaging>
<modules>
<module>03-01-service-a</module>
<module>03-02-service-b</module>
<module>03-03-service-a2</module>
<module>03-04-service-b2</module>
</modules>
<dependencies>
<!-- 服务的策略编排插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-strategy-starter-service</artifactId>
<version>${discovery.version}</version>
</dependency>
</dependencies>
</project>
\ 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">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.dankal</groupId>
<artifactId>test-in-discovery</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>01-test-in-discovery-common</module>
<module>02-test-in-discovery-gateway</module>
<module>03-test-in-discovery-service</module>
</modules>
<packaging>pom</packaging>
<description>蛋壳创意科技-技术测试-Discovery</description>
<properties>
<discovery.version>6.3.1</discovery.version>
<spring.cloud.version>Greenwich.SR5</spring.cloud.version>
<spring.cloud.alibaba.version>2.1.0.RELEASE</spring.cloud.alibaba.version>
<spring.boot.version>2.1.8.RELEASE</spring.boot.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>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring.cloud.alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<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
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