Commit b145c175 by 仲光辉

第一次提交:关于日志记录与分布式链路跟踪的小尝试 2020/10/19 16:19

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*
.idea
*.iml
**/target
**/**/target
logs
<?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>01-test-in-sleuth-common</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>01-01-common-util</artifactId>
<dependencies>
<!--spring-cloud-nacos-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--spring-cloud-zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!--spring-cloud-stream-rabbit-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<!--logstash-gelf-->
<dependency>
<groupId>biz.paluch.logging</groupId>
<artifactId>logstash-gelf</artifactId>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.test.common.domain;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* Person domain
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/19
*/
@Data
@Accessors(chain = true)
public class Person implements Serializable {
private static final long serialVersionUID = -1993617468528279937L;
/**
* id
*/
private Long id;
/**
* 姓名
*/
private String name;
/**
* 公司
*/
private String company = "蛋壳创意科技";
/**
* 其TA信息
*/
private String other;
}
<?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>01-test-in-sleuth-common</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>01-02-service-util</artifactId>
<dependencies>
<!--spring-boot-web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--javax-faces-api-->
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<scope>provided</scope>
</dependency>
<!--inner dependence-->
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>01-01-common-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.test.common.service.advice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletResponse;
/**
* {@link RestControllerAdvice,Slf4j}
* 服务全局异常处理
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/19
*/
@Slf4j
@RestControllerAdvice(basePackages = {"cn.dankal.test"})
public class GlobalExceptionAdvice {
/**
* 处理 全局 Exception 异常
*
* @param exception Exception Object
* @return 异常信息:[exception.getCause().getMessage(),exception.getMessage()]
*/
@ExceptionHandler({Exception.class})
public String handlerException(Exception exception, HttpServletResponse response) {
Throwable exceptionCause = exception.getCause();
String exceptionInfo = (exceptionCause == null ? "发生异常" : exceptionCause.getMessage()) + " --> " + exception.getMessage();
log.error("throws a exception : {}", exceptionInfo);
response.setContentType("application/json; charset=UTF-8");
return exceptionInfo;
}
}
package cn.dankal.test.common.service.aspect;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* {@link Target,Retention}
* <p>
* 此注解标注使用在标有诸如:
* <br/>
* - {@link org.springframework.web.bind.annotation.RequestMapping}
* <br/>
* - {@link org.springframework.web.bind.annotation.GetMapping}
* <br/>
* - {@link org.springframework.web.bind.annotation.PostMapping}
* <br/>
* - {@link org.springframework.web.bind.annotation.PutMapping}
* <br/>
* - {@link org.springframework.web.bind.annotation.DeleteMapping}
* </p>
* 等 SpringMVC 处理器方法注解的方法上 用于记录 请求日志 和 处理请求异常日志
* <br/>
* <br/>
* 当前注解{@link DoRequestLog} 是 Request日志切面${@link RequestLogAspect} 的 切入点表达式
* <br/>
* <br/>
* {@link Around}: 实现 请求日志打印 {@link cn.dankal.test.common.service.aspect.RequestLogAspect.RequestInfo}
* <br/>
* <br/>
* {@link AfterThrowing} : 实现 异常日志打印 {@link cn.dankal.test.common.service.aspect.RequestLogAspect.RequestErrorInfo}
* <br/>
* <br/>
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/19
* @see RequestLogAspect
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface DoRequestLog {
}
package cn.dankal.test.common.service.aspect;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.experimental.Accessors;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* {@link Aspect,Component}
* 请求日志切面类
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/19
* @see DoRequestLog
*/
@Aspect
@Component
public class RequestLogAspect {
/**
* LOGGER
*/
private final static Logger LOGGER = LoggerFactory.getLogger(RequestLogAspect.class);
/**
* 切入点表达式
*/
@Pointcut("@annotation(cn.dankal.test.common.service.aspect.DoRequestLog)")
public void pointcut() {
}
/**
* Spring 环绕通知: 打印请求信息
*
* @param proceedingJoinPoint ProceedingJoinPoint
* @return 目标方法返回值
* @throws Throwable 目标方法执行异常
* @see ProceedingJoinPoint,RequestContextHolder
*/
@Around("pointcut()")
public Object doAround2RequestLog(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
// HttpServletRequest
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
Assert.notNull(attributes, "doAround2RequestLog --> 获取 ServletRequestAttributes 失败!!!");
HttpServletRequest request = attributes.getRequest();
Object result = proceedingJoinPoint.proceed();
// HttpServletRequest --> RequestInfo
RequestInfo requestInfo = new RequestInfo()
.setIp(request.getRemoteAddr())
.setUrl(request.getRequestURL().toString())
.setHttpMethod(request.getMethod())
.setClassMethod(String.format("%s.%s", proceedingJoinPoint.getSignature().getDeclaringTypeName(),
proceedingJoinPoint.getSignature().getName()))
.setRequestParams(getRequestParamsByProceedingJoinPoint(proceedingJoinPoint))
.setResult(result)
.setTimeCost(System.currentTimeMillis() - startTime);
LOGGER.info("Request-Info : {}", JSON.toJSONString(requestInfo));
return result;
}
/**
* Spring 异常返回通知: 打印错误日志信息
*
* @param joinPoint JoinPoint
* @param throwable Throwable
* @see JoinPoint,Throwable
*/
@AfterThrowing(pointcut = "pointcut()", throwing = "throwable")
public void doAfterThrow2RequestLog(JoinPoint joinPoint, Throwable throwable) {
// HttpServletRequest
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
Assert.notNull(attributes, "doAfterThrow2RequestLog --> 获取 ServletRequestAttributes 失败!!!");
HttpServletRequest request = attributes.getRequest();
// HttpServletRequest --> RequestErrorInfo
RequestErrorInfo requestErrorInfo = new RequestErrorInfo()
.setIp(request.getRemoteAddr())
.setUrl(request.getRequestURL().toString())
.setHttpMethod(request.getMethod())
.setClassMethod(String.format("%s.%s", joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName()))
.setRequestParams(getRequestParamsByJoinPoint(joinPoint))
.setThrowable(throwable);
LOGGER.error("Error-Request-Info : {}", JSON.toJSONString(requestErrorInfo));
}
/**
* 通过 ProceedingJoinPoint 获取请求参数信息
*
* @param proceedingJoinPoint ProceedingJoinPoint
* @return 封装了请求信息的 Map<String, Object>
* @see ProceedingJoinPoint
*/
private Map<String, Object> getRequestParamsByProceedingJoinPoint(ProceedingJoinPoint proceedingJoinPoint) {
//参数名
String[] paramNames = ((MethodSignature) proceedingJoinPoint.getSignature()).getParameterNames();
//参数值
Object[] paramValues = proceedingJoinPoint.getArgs();
return buildRequestParamInfo(paramNames, paramValues);
}
/**
* 通过 JoinPoint 后期请求参数信息
*
* @param joinPoint JoinPoint
* @return 装了请求信息的 Map<String, Object>
* @see JoinPoint
*/
private Map<String, Object> getRequestParamsByJoinPoint(JoinPoint joinPoint) {
//参数名
String[] paramNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames();
//参数值
Object[] paramValues = joinPoint.getArgs();
return buildRequestParamInfo(paramNames, paramValues);
}
/**
* 构建 请求参数信息
*
* @param paramNames 请求参数名称数组
* @param paramValues 请求参数值数组
* @return Map<String, Object>
*/
private Map<String, Object> buildRequestParamInfo(String[] paramNames, Object[] paramValues) {
Map<String, Object> requestParams = new HashMap<>(1 << 5);
for (int i = 0; i < paramNames.length; i++) {
Object value = paramValues[i];
//如果是文件对象
if (value instanceof MultipartFile) {
MultipartFile file = (MultipartFile) value;
//获取文件名
value = file.getOriginalFilename();
}
requestParams.put(paramNames[i], value);
}
return requestParams;
}
/**
* 请求信息记录
*/
@Data
@Accessors(chain = true)
static class RequestInfo {
/**
* 请求 ip
*/
private String ip;
/**
* 请求 url
*/
private String url;
/**
* 请求方式
*/
private String httpMethod;
/**
* 处理器方法
*/
private String classMethod;
/**
* 请求参数
*/
private Object requestParams;
/**
* 响应结果
*/
private Object result;
/**
* 请求处理消耗时间
*/
private Long timeCost;
}
/**
* 请求错误信息记录
*/
@Data
@Accessors(chain = true)
static class RequestErrorInfo {
/**
* 请求 ip
*/
private String ip;
/**
* 请求 url
*/
private String url;
/**
* 请求方式
*/
private String httpMethod;
/**
* 处理器方法
*/
private String classMethod;
/**
* 请求参数
*/
private Object requestParams;
/**
* 异常信息
*/
private Throwable throwable;
}
}
<?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-sleuth</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>01-test-in-sleuth-common</artifactId>
<packaging>pom</packaging>
<description>蛋壳创意科技技术测试-SpringCloudSleuth-common</description>
<modules>
<module>01-01-common-util</module>
<module>01-02-service-util</module>
</modules>
</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">
<parent>
<artifactId>test-in-sleuth</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>02-test-in-sleuth-gateway</artifactId>
<description>蛋壳创意科技技术测试-SpringCloudSleuth-gateway</description>
<dependencies>
<!--spring-cloud-gateway-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!--inner dependence-->
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>01-01-common-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package cn.dankal.test.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* {@link SpringBootApplication,EnableDiscoveryClient}
* 网关启动类
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"cn.dankal.test"})
public class TestSleuthGateway {
public static void main(String[] args) {
SpringApplication.run(TestSleuthGateway.class, args);
}
}
server:
port: 80
spring:
cloud:
gateway:
routes:
- id: user-service
uri: lb://user-service
predicates:
- Path=/user/**
- id: order-service
uri: lb://order-service
predicates:
- Path=/order/**
nacos:
discovery:
server-addr: register.mercymodest.com:58080
zipkin:
sender:
type: rabbit
sleuth:
sampler:
probability: 1
web:
client:
enabled: true
rabbitmq:
host: mq.mercymodest.com
port: 55672
username: guest
password: guest
virtual-host: /
\ No newline at end of file
spring.application.name=test-in-sleuth-gateway
spring.cloud.nacos.config.server-addr=register.mercymodest.com:58080
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
<!--logstash-gelf config-->
<contextName>sleuth-gateway</contextName>
<jmxConfigurator/>
<appender name="GELF" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
<host>udp:192.168.128.3</host>
<port>12201</port>
<version>1.1</version>
<originHost>sleuth-gateway</originHost>
<facility>sleuth-gateway</facility>
<extractStackTrace>true</extractStackTrace>
<filterStackTrace>true</filterStackTrace>
<mdcProfiling>true</mdcProfiling>
<timestampPattern>yyyy-MM-dd HH:mm:ss,SSS</timestampPattern>
<maximumMessageSize>8192</maximumMessageSize>
<!-- This are static fields -->
<additionalFields>sleuth-gateway=01,ip=120.23.56.111,sleuth-gateway-version=v1.0.0</additionalFields>
<!-- Optional: Specify field types -->
<additionalFieldTypes>field-Name1=String,field-Name2=Double,field-Name3=Long</additionalFieldTypes>
<!-- This are fields using MDC -->
<mdcFields>mdcField1,mdcField2</mdcFields>
<dynamicMdcFields>mdc.*,(mdc|MDC)fields</dynamicMdcFields>
<dynamicMdcFieldTypes>my_field.*=String,business\..*\.field=double</dynamicMdcFieldTypes>
<includeFullMdc>true</includeFullMdc>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Simple file output -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>logs/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 64 MB -->
<maxFileSize>10 MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- Safely log to the same file from multiple JVMs. Degrades performance! -->
<prudent>true</prudent>
</appender>
<!-- Console output -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern> %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable</pattern>
</encoder>
<!-- Only log level INFO and above -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Enable FILE and STDOUT appenders for all log messages.
By default, only log at level INFO and above. -->
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
<appender-ref ref="GELF" />
</root>
<!-- For loggers in the these namespaces, log at all levels. -->
<logger name="user" level="ALL" />
<!-- To log pedestal internals, enable this and change ThresholdFilter to DEBUG
<logger name="pedestal" level="ALL" />
-->
</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-sleuth-user</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>03-01-user-service-01</artifactId>
</project>
\ No newline at end of file
package cn.dankal.test.user;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* {@link SpringBootApplication,EnableDiscoveryClient}
* User 服务启动类
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@EnableDiscoveryClient
@EnableFeignClients("cn.dankal.test")
@SpringBootApplication(scanBasePackages = {"cn.dankal.test"})
public class UserServiceApplication01 {
public static void main(String[] args) {
SpringApplication.run(UserServiceApplication01.class, args);
}
}
package cn.dankal.test.user.controller;
import cn.dankal.test.client.order.OrderServiceClient;
import cn.dankal.test.common.domain.Person;
import cn.dankal.test.common.service.aspect.DoRequestLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* {@link RestController}
* UserController
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
/**
* orderServiceClient
*/
private final OrderServiceClient orderServiceClient;
public UserController(OrderServiceClient orderServiceClient) {
this.orderServiceClient = orderServiceClient;
}
@DoRequestLog
@GetMapping("/{userId}")
public Person getUserById(@PathVariable("userId") Long userId) {
log.info("user service 01 get user: {}", userId);
String orderId = orderServiceClient.getOrderId(userId);
return new Person()
.setId(userId)
.setName("ZGH.MercyModest")
.setOther("user-service-01 --> " + orderId);
}
}
server:
port: 7001
spring:
application:
name: user-service
cloud:
nacos:
discovery:
server-addr: register.mercymodest.com:58080
zipkin:
sender:
type: rabbit
sleuth:
sampler:
probability: 1
web:
client:
enabled: true
rabbitmq:
host: mq.mercymodest.com
port: 55672
username: guest
password: guest
virtual-host: /
\ No newline at end of file
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
<!--logstash-gelf config-->
<contextName>user-service-01</contextName>
<jmxConfigurator/>
<appender name="GELF" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
<host>udp:192.168.128.3</host>
<port>12201</port>
<version>1.1</version>
<originHost>user-service-01</originHost>
<facility>user-service-01</facility>
<extractStackTrace>true</extractStackTrace>
<filterStackTrace>true</filterStackTrace>
<mdcProfiling>true</mdcProfiling>
<timestampPattern>yyyy-MM-dd HH:mm:ss,SSS</timestampPattern>
<maximumMessageSize>8192</maximumMessageSize>
<!-- This are static fields -->
<additionalFields>user-service=01,ip=120.23.56.28,user-service-01-version=v1.0.0</additionalFields>
<!-- Optional: Specify field types -->
<additionalFieldTypes>field-Name1=String,field-Name2=Double,field-Name3=Long</additionalFieldTypes>
<!-- This are fields using MDC -->
<mdcFields>mdcField1,mdcField2</mdcFields>
<dynamicMdcFields>mdc.*,(mdc|MDC)fields</dynamicMdcFields>
<dynamicMdcFieldTypes>my_field.*=String,business\..*\.field=double</dynamicMdcFieldTypes>
<includeFullMdc>true</includeFullMdc>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Simple file output -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>logs/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 64 MB -->
<maxFileSize>10 MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- Safely log to the same file from multiple JVMs. Degrades performance! -->
<prudent>true</prudent>
</appender>
<!-- Console output -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern> %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable</pattern>
</encoder>
<!-- Only log level INFO and above -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Enable FILE and STDOUT appenders for all log messages.
By default, only log at level INFO and above. -->
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
<appender-ref ref="GELF" />
</root>
<!-- For loggers in the these namespaces, log at all levels. -->
<logger name="user" level="ALL" />
<!-- To log pedestal internals, enable this and change ThresholdFilter to DEBUG
<logger name="pedestal" level="ALL" />
-->
</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-sleuth-user</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>03-02-user-service-02</artifactId>
</project>
\ No newline at end of file
package cn.dankal.test.user;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* {@link SpringBootApplication,EnableDiscoveryClient}
* User 服务启动类
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@EnableDiscoveryClient
@EnableFeignClients("cn.dankal.test")
@SpringBootApplication(scanBasePackages = {"cn.dankal.test"})
public class UserServiceApplication02 {
public static void main(String[] args) {
SpringApplication.run(UserServiceApplication02.class, args);
}
}
package cn.dankal.test.user.controller;
import cn.dankal.test.client.order.OrderServiceClient;
import cn.dankal.test.common.domain.Person;
import cn.dankal.test.common.service.aspect.DoRequestLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* {@link RestController}
* UserController
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
/**
* orderServiceClient
*/
private final OrderServiceClient orderServiceClient;
public UserController(OrderServiceClient orderServiceClient) {
this.orderServiceClient = orderServiceClient;
}
@DoRequestLog
@GetMapping("/{userId}")
public Person getUserById(@PathVariable("userId") Long userId) throws Throwable {
if (1 == userId) {
orderServiceClient.getOrderId(userId);
throw new Throwable("user-service-02: --> 抛出异常测试异常日志的打印");
}
log.info("user service 02 get user: {}", userId);
String orderId = orderServiceClient.getOrderId(userId);
return new Person()
.setId(userId)
.setName("ZGH.MercyModest")
.setOther("user-service-02 --> " + orderId);
}
}
server:
port: 7002
spring:
application:
name: user-service
cloud:
nacos:
discovery:
server-addr: register.mercymodest.com:58080
zipkin:
sender:
type: rabbit
sleuth:
sampler:
probability: 1
web:
client:
enabled: true
rabbitmq:
host: mq.mercymodest.com
port: 55672
username: guest
password: guest
virtual-host: /
\ No newline at end of file
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
<!--logstash-gelf config-->
<contextName>user-service-02</contextName>
<jmxConfigurator/>
<appender name="GELF" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
<host>udp:192.168.128.3</host>
<port>12201</port>
<version>1.1</version>
<originHost>user-service-02</originHost>
<facility>user-service-02</facility>
<extractStackTrace>true</extractStackTrace>
<filterStackTrace>true</filterStackTrace>
<mdcProfiling>true</mdcProfiling>
<timestampPattern>yyyy-MM-dd HH:mm:ss,SSS</timestampPattern>
<maximumMessageSize>8192</maximumMessageSize>
<!-- This are static fields -->
<additionalFields>user-service=02,ip=120.23.56.128,user-service-02-version=v1.0.0</additionalFields>
<!-- Optional: Specify field types -->
<additionalFieldTypes>field-Name1=String,field-Name2=Double,field-Name3=Long</additionalFieldTypes>
<!-- This are fields using MDC -->
<mdcFields>mdcField1,mdcField2</mdcFields>
<dynamicMdcFields>mdc.*,(mdc|MDC)fields</dynamicMdcFields>
<dynamicMdcFieldTypes>my_field.*=String,business\..*\.field=double</dynamicMdcFieldTypes>
<includeFullMdc>true</includeFullMdc>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Simple file output -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>logs/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 64 MB -->
<maxFileSize>10 MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- Safely log to the same file from multiple JVMs. Degrades performance! -->
<prudent>true</prudent>
</appender>
<!-- Console output -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern> %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable</pattern>
</encoder>
<!-- Only log level INFO and above -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Enable FILE and STDOUT appenders for all log messages.
By default, only log at level INFO and above. -->
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
<appender-ref ref="GELF" />
</root>
<!-- For loggers in the these namespaces, log at all levels. -->
<logger name="user" level="ALL" />
<!-- To log pedestal internals, enable this and change ThresholdFilter to DEBUG
<logger name="pedestal" level="ALL" />
-->
</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-sleuth</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>03-test-in-sleuth-user</artifactId>
<packaging>pom</packaging>
<description>蛋壳创意科技技术测试-SpringCloudSleuth-user</description>
<modules>
<module>03-01-user-service-01</module>
<module>03-02-user-service-02</module>
</modules>
<dependencies>
<!--inner project-->
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>01-02-service-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>05-01-order-service-client</artifactId>
<version>1.0-SNAPSHOT</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">
<parent>
<artifactId>04-test-in-sleuth-order</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>04-01-order-service-01</artifactId>
</project>
\ No newline at end of file
package cn.dankal.test.order;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* {@link SpringBootApplication}
* Order 服务 启动类
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = "cn.dankal.test")
public class OrderServiceApplication01 {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication01.class, args);
}
}
package cn.dankal.test.order.controller;
import cn.dankal.test.common.service.aspect.DoRequestLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.UUID;
/**
* {@link RestController}
* <p>
* OrderController
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
@DoRequestLog
@GetMapping("/{userId}")
public String getOrderId(@PathVariable("userId") Long userId) {
log.info("order service 01 getOrderId: {}", userId);
return "order service 01 "+userId + " --> "+ UUID.randomUUID().toString().replace("-", "");
}
}
server:
port: 8001
spring:
application:
name: order-service
cloud:
nacos:
discovery:
server-addr: register.mercymodest.com:58080
zipkin:
sender:
type: rabbit
sleuth:
sampler:
probability: 1
web:
client:
enabled: true
rabbitmq:
host: mq.mercymodest.com
port: 55672
username: guest
password: guest
virtual-host: /
\ No newline at end of file
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
<!--logstash-gelf config-->
<contextName>order-service-01</contextName>
<jmxConfigurator/>
<appender name="GELF" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
<host>udp:192.168.128.3</host>
<port>12201</port>
<version>1.1</version>
<originHost>order-service-01</originHost>
<facility>order-service-01</facility>
<extractStackTrace>true</extractStackTrace>
<filterStackTrace>true</filterStackTrace>
<mdcProfiling>true</mdcProfiling>
<timestampPattern>yyyy-MM-dd HH:mm:ss,SSS</timestampPattern>
<maximumMessageSize>8192</maximumMessageSize>
<!-- This are static fields -->
<additionalFields>order-service=01,ip=120.23.56.132,order-service-01-version=v1.0.0</additionalFields>
<!-- Optional: Specify field types -->
<additionalFieldTypes>field-Name1=String,field-Name2=Double,field-Name3=Long</additionalFieldTypes>
<!-- This are fields using MDC -->
<mdcFields>mdcField1,mdcField2</mdcFields>
<dynamicMdcFields>mdc.*,(mdc|MDC)fields</dynamicMdcFields>
<dynamicMdcFieldTypes>my_field.*=String,business\..*\.field=double</dynamicMdcFieldTypes>
<includeFullMdc>true</includeFullMdc>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Simple file output -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>logs/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 64 MB -->
<maxFileSize>10 MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- Safely log to the same file from multiple JVMs. Degrades performance! -->
<prudent>true</prudent>
</appender>
<!-- Console output -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern> %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable</pattern>
</encoder>
<!-- Only log level INFO and above -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Enable FILE and STDOUT appenders for all log messages.
By default, only log at level INFO and above. -->
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
<appender-ref ref="GELF" />
</root>
<!-- For loggers in the these namespaces, log at all levels. -->
<logger name="user" level="ALL" />
<!-- To log pedestal internals, enable this and change ThresholdFilter to DEBUG
<logger name="pedestal" level="ALL" />
-->
</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>04-test-in-sleuth-order</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>04-02-order-service-02</artifactId>
</project>
\ No newline at end of file
package cn.dankal.test.order;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* {@link SpringBootApplication}
* Order 服务 启动类
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"cn.dankal.test"})
public class OrderServiceApplication02 {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication02.class, args);
}
}
package cn.dankal.test.order.controller;
import cn.dankal.test.common.service.aspect.DoRequestLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.UUID;
/**
* {@link RestController}
* <p>
* OrderController
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
@DoRequestLog
@GetMapping("/{userId}")
public String getOrderId(@PathVariable("userId") Long userId) {
log.info("order service 02 getOrderId: {}", userId);
if (1 == userId) {
throw new RuntimeException("order-service-02: --> 抛出异常测试异常日志的打印");
}
return "order service 02 "+userId + " --> "+ UUID.randomUUID().toString().replace("-", "");
}
}
server:
port: 8002
spring:
application:
name: order-service
cloud:
nacos:
discovery:
server-addr: register.mercymodest.com:58080
zipkin:
sender:
type: rabbit
sleuth:
sampler:
probability: 1
web:
client:
enabled: true
rabbitmq:
host: mq.mercymodest.com
port: 55672
username: guest
password: guest
virtual-host: /
\ No newline at end of file
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
<!--logstash-gelf config-->
<contextName>order-service-02</contextName>
<jmxConfigurator/>
<appender name="GELF" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
<host>udp:192.168.128.3</host>
<port>12201</port>
<version>1.1</version>
<originHost>order-service-02</originHost>
<facility>order-service-02</facility>
<extractStackTrace>true</extractStackTrace>
<filterStackTrace>true</filterStackTrace>
<mdcProfiling>true</mdcProfiling>
<timestampPattern>yyyy-MM-dd HH:mm:ss,SSS</timestampPattern>
<maximumMessageSize>8192</maximumMessageSize>
<!-- This are static fields -->
<additionalFields>order-service=02,ip=120.23.56.152,order-service-02-version=v1.0.0</additionalFields>
<!-- Optional: Specify field types -->
<additionalFieldTypes>field-Name1=String,field-Name2=Double,field-Name3=Long</additionalFieldTypes>
<!-- This are fields using MDC -->
<mdcFields>mdcField1,mdcField2</mdcFields>
<dynamicMdcFields>mdc.*,(mdc|MDC)fields</dynamicMdcFields>
<dynamicMdcFieldTypes>my_field.*=String,business\..*\.field=double</dynamicMdcFieldTypes>
<includeFullMdc>true</includeFullMdc>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Simple file output -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>logs/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 64 MB -->
<maxFileSize>10 MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- Safely log to the same file from multiple JVMs. Degrades performance! -->
<prudent>true</prudent>
</appender>
<!-- Console output -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern> %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable</pattern>
</encoder>
<!-- Only log level INFO and above -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!-- Enable FILE and STDOUT appenders for all log messages.
By default, only log at level INFO and above. -->
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
<appender-ref ref="GELF" />
</root>
<!-- For loggers in the these namespaces, log at all levels. -->
<logger name="user" level="ALL" />
<!-- To log pedestal internals, enable this and change ThresholdFilter to DEBUG
<logger name="pedestal" level="ALL" />
-->
</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-sleuth</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>04-test-in-sleuth-order</artifactId>
<packaging>pom</packaging>
<description>蛋壳创意科技技术测试-SpringCloudSleuth-order</description>
<modules>
<module>04-01-order-service-01</module>
<module>04-02-order-service-02</module>
</modules>
<dependencies>
<!--inner dependence-->
<dependency>
<groupId>cn.dankal</groupId>
<artifactId>01-02-service-util</artifactId>
<version>1.0-SNAPSHOT</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">
<parent>
<artifactId>05-test-in-sleuth-client</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>05-01-order-service-client</artifactId>
</project>
\ No newline at end of file
package cn.dankal.test.client.order;
import cn.dankal.test.client.order.fallback.OrderServiceClientFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* TODO
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@FeignClient(value = "order-service", fallback = OrderServiceClientFallback.class)
public interface OrderServiceClient {
/**
* 通过 userId 获取订单号
*
* @param userId userId
* @return the test orderId
*/
@GetMapping("/order/{userId}")
String getOrderId(@PathVariable("userId") Long userId);
}
package cn.dankal.test.client.order.fallback;
import cn.dankal.test.client.order.OrderServiceClient;
import org.springframework.stereotype.Component;
/**
* {@link OrderServiceClient,Component}
* Order Service 服务降级
*
* @author ZGH.MercyModest
* @version V1.0.0
* @create 2020/10/18
*/
@Component
public class OrderServiceClientFallback implements OrderServiceClient {
@Override
public String getOrderId(Long userId) {
return "return from OrderServiceClientFallback:getOrderId:" + userId;
}
}
<?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-sleuth</artifactId>
<groupId>cn.dankal</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>05-test-in-sleuth-client</artifactId>
<packaging>pom</packaging>
<description>蛋壳创意科技技术测试-SpringCloudSleuth-client</description>
<modules>
<module>05-01-order-service-client</module>
</modules>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</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>
<modules>
<module>01-test-in-sleuth-common</module>
<module>02-test-in-sleuth-gateway</module>
<module>03-test-in-sleuth-user</module>
<module>04-test-in-sleuth-order</module>
<module>05-test-in-sleuth-client</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/>
</parent>
<groupId>cn.dankal</groupId>
<artifactId>test-in-sleuth</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<description>蛋壳创意科技技术测试--SpringCloudSleuth[分布式链路跟踪]</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR5</spring-cloud.version>
<spring-cloud.alibaba.version>2.1.0.RELEASE</spring-cloud.alibaba.version>
<logstash-gelf.version>1.14.0</logstash-gelf.version>
<hutool-core.version>5.4.0</hutool-core.version>
<javax.faces-api.version>2.2</javax.faces-api.version>
</properties>
<dependencyManagement>
<dependencies>
<!--spring-cloud-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring-cloud-alibaba-->
<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>
<!--logstash-gelf-->
<dependency>
<groupId>biz.paluch.logging</groupId>
<artifactId>logstash-gelf</artifactId>
<version>${logstash-gelf.version}</version>
</dependency>
<!--hutool-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>${hutool-core.version}</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>${javax.faces-api.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</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