|
|
@@ -1,8 +1,6 @@
|
|
|
package cn.reghao.tnb.gateway.log;
|
|
|
|
|
|
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
import cn.reghao.tnb.gateway.log.model.GatewayLog;
|
|
|
-import cn.reghao.tnb.gateway.mq.RabbitProducer;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.cloud.gateway.route.Route;
|
|
|
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
|
|
|
@@ -16,9 +14,6 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.URI;
|
|
|
-import java.time.Duration;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
@@ -36,7 +31,7 @@ public class GatewayLogService {
|
|
|
}
|
|
|
|
|
|
public void saveGatewayLog(GatewayLog gatewayLog) {
|
|
|
- //rabbitProducer.sendGatewayLog(gatewayLog);
|
|
|
+ rabbitProducer.sendGatewayLog(gatewayLog);
|
|
|
}
|
|
|
|
|
|
public void setGatewayLog(ServerWebExchange exchange) {
|
|
|
@@ -53,10 +48,10 @@ public class GatewayLogService {
|
|
|
});
|
|
|
gatewayLog.setResponseHeaders(responseHeaders);
|
|
|
|
|
|
- LocalDateTime responseTime = LocalDateTime.now();
|
|
|
+ long responseTime = System.currentTimeMillis();
|
|
|
gatewayLog.setResponseTime(responseTime);
|
|
|
// 计算执行时间
|
|
|
- long executeTime = Duration.between(gatewayLog.getRequestTime(), responseTime).toMillis();
|
|
|
+ long executeTime = responseTime-gatewayLog.getRequestTime();
|
|
|
gatewayLog.setExecuteTime(executeTime);
|
|
|
saveGatewayLog(gatewayLog);
|
|
|
}
|
|
|
@@ -82,7 +77,7 @@ public class GatewayLogService {
|
|
|
String requestId = headers.get("x-request-id").get(0);
|
|
|
gatewayLog.setRequestId(requestId);
|
|
|
String requestTimeStr = headers.get("x-request-time").get(0);
|
|
|
- LocalDateTime requestTime = DateTimeConverter.localDateTime(Long.parseLong(requestTimeStr));
|
|
|
+ long requestTime = Long.parseLong(requestTimeStr);
|
|
|
gatewayLog.setRequestTime(requestTime);
|
|
|
|
|
|
InetSocketAddress remote = exchange.getRequest().getRemoteAddress();
|