Selaa lähdekoodia

Merge branch 'dev' of yeshijie/jw2.0 into dev

yeshijie 6 vuotta sitten
vanhempi
commit
0dd3377fcb

+ 34 - 0
common/common-tracer/pom.xml

@ -0,0 +1,34 @@
<?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>wlyy-parent-pom</artifactId>
        <groupId>com.yihu.jw</groupId>
        <version>2.0.0</version>
        <relativePath>../../wlyy-parent-pom/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>common-tracer</artifactId>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
    </dependencies>
</project>

+ 50 - 0
common/common-tracer/src/main/java/com/yihu/jw/advice/HttpAdvice.java

@ -0,0 +1,50 @@
package com.yihu.jw.advice;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
 * Created by yeshijie on 2018/9/14
 */
@Aspect
@Component
public class HttpAdvice {
    @Autowired
    private Tracer tracer;
    @Autowired
    private ObjectMapper objectMapper;
    private Logger logger = LoggerFactory.getLogger(HttpAdvice.class);
    @Around("within(@org.springframework.web.bind.annotation.RestController *)")
    public Object process(ProceedingJoinPoint point) throws Throwable {
        //保存入参
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        tracer.getCurrentSpan().logEvent(objectMapper.writeValueAsString(request.getParameterMap()));
        //访问目标方法的参数:
        Object[] args = point.getArgs();
        Long strartTime = System.currentTimeMillis();
        Object returnValue = point.proceed(args);
        Long endTime = System.currentTimeMillis();
        //保存响应
        tracer.getCurrentSpan().logEvent(objectMapper.writeValueAsString(returnValue));
        //保存响应时间
        tracer.getCurrentSpan().logEvent("executeTime:"+(endTime - strartTime));
        return returnValue;
    }
}

+ 8 - 4
svr/svr-base/pom.xml

@ -54,10 +54,10 @@
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <!--<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>-->
        <!--<dependency>-->
            <!--<groupId>org.springframework.cloud</groupId>-->
            <!--<artifactId>spring-cloud-starter-zipkin</artifactId>-->
        <!--</dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-activemq</artifactId>
@ -92,6 +92,10 @@
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-web</artifactId>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>com.yihu.jw</groupId>-->
            <!--<artifactId>common-tracer</artifactId>-->
        <!--</dependency>-->
        <!-- 文件服务器 -->
        <dependency>
            <groupId>com.yihu</groupId>

+ 1 - 0
wlyy-lib-parent-pom/pom.xml

@ -25,6 +25,7 @@
        <module>../common/common-util</module>
        <module>../common/common-fegin</module>
        <module>../common/common-web</module>
        <module>../common/common-tracer</module>
    </modules>
</project>

+ 5 - 0
wlyy-parent-pom/pom.xml

@ -161,6 +161,11 @@
                <artifactId>common-web</artifactId>
                <version>${version.wlyy-common}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.jw</groupId>
                <artifactId>common-tracer</artifactId>
                <version>${version.wlyy-common}</version>
            </dependency>
            <!-- Jkzl Starter -->
            <dependency>