v2.1.1 kafka日志发送改为异步,添加事务排除,添加try catch异常拦截,修改异步线程池参数
This commit is contained in:
@ -7,13 +7,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud-jpa-starter</artifactId>
|
<artifactId>mall-ebtp-cloud-jpa-starter</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<name>mall-ebtp-cloud-jpa-starter</name>
|
<name>mall-ebtp-cloud-jpa-starter</name>
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,13 +8,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud-kafka-starter</artifactId>
|
<artifactId>mall-ebtp-cloud-kafka-starter</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<name>mall-ebtp-cloud-kafka-starter</name>
|
<name>mall-ebtp-cloud-kafka-starter</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud</artifactId>
|
<artifactId>mall-ebtp-cloud</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>mall-ebtp-cloud-parent</name>
|
<name>mall-ebtp-cloud-parent</name>
|
||||||
|
|
||||||
@ -21,22 +21,22 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud-jpa-starter</artifactId>
|
<artifactId>mall-ebtp-cloud-jpa-starter</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud-kafka-starter</artifactId>
|
<artifactId>mall-ebtp-cloud-kafka-starter</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
||||||
<artifactId>uboot-common</artifactId>
|
<artifactId>uboot-common</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
||||||
<artifactId>uboot-core</artifactId>
|
<artifactId>uboot-core</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
2
pom.xml
2
pom.xml
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud</artifactId>
|
<artifactId>mall-ebtp-cloud</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>mall-ebtp-cloud</name>
|
<name>mall-ebtp-cloud</name>
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
||||||
<artifactId>uboot-common</artifactId>
|
<artifactId>uboot-common</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<name>uboot-common</name>
|
<name>uboot-common</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -3,6 +3,7 @@ package com.chinaunicom.mall.ebtp.common.log.producer;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.kafka.core.KafkaTemplate;
|
import org.springframework.kafka.core.KafkaTemplate;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,7 +21,7 @@ public class OperationLogKafkaProducer {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private KafkaTemplate<String, String> kafkaTemplate;
|
private KafkaTemplate<String, String> kafkaTemplate;
|
||||||
|
|
||||||
|
@Async
|
||||||
public void send(String message) {
|
public void send(String message) {
|
||||||
kafkaTemplate.send(TOPIC, message)
|
kafkaTemplate.send(TOPIC, message)
|
||||||
.addCallback(success -> {
|
.addCallback(success -> {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.chinaunicom.mall.ebtp.common.log.service.impl;
|
package com.chinaunicom.mall.ebtp.common.log.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||||
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
|
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
|
||||||
import com.chinaunicom.mall.ebtp.common.constant.CommonConstants;
|
import com.chinaunicom.mall.ebtp.common.constant.CommonConstants;
|
||||||
@ -12,10 +13,13 @@ import com.chinaunicom.mall.ebtp.common.log.service.OperationLogService;
|
|||||||
import com.chinaunicom.mall.ebtp.common.util.HttpContextUtils;
|
import com.chinaunicom.mall.ebtp.common.util.HttpContextUtils;
|
||||||
import com.chinaunicom.mall.ebtp.common.util.JsonUtils;
|
import com.chinaunicom.mall.ebtp.common.util.JsonUtils;
|
||||||
import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
|
import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -29,6 +33,8 @@ import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.
|
|||||||
* @author f
|
* @author f
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
public class OperationLogServiceImpl implements OperationLogService {
|
public class OperationLogServiceImpl implements OperationLogService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -43,38 +49,42 @@ public class OperationLogServiceImpl implements OperationLogService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOperationLog(OperationLog operationLog) {
|
public void addOperationLog(OperationLog operationLog) {
|
||||||
if (operationLog.getMethod() == null) {
|
try {
|
||||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
if (operationLog.getMethod() == null) {
|
||||||
for (int i = 1; i < stackTrace.length; i++) {
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
StackTraceElement element = stackTrace[i];
|
for (int i = 1; i < stackTrace.length; i++) {
|
||||||
if (!element.getClassName().equals(OperationLogServiceImpl.class.getName())) {
|
StackTraceElement element = stackTrace[i];
|
||||||
operationLog.setPackageName(element.getClassName());
|
if (!element.getClassName().equals(OperationLogServiceImpl.class.getName())) {
|
||||||
operationLog.setMethod(element.getMethodName());
|
operationLog.setPackageName(element.getClassName());
|
||||||
break;
|
operationLog.setMethod(element.getMethodName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (operationLog.getMethod() == null) {
|
if (operationLog.getMethod() == null) {
|
||||||
StackTraceElement element = Thread.currentThread().getStackTrace()[1];
|
StackTraceElement element = Thread.currentThread().getStackTrace()[1];
|
||||||
operationLog.setPackageName(element.getClassName());
|
operationLog.setPackageName(element.getClassName());
|
||||||
operationLog.setMethod(element.getMethodName());
|
operationLog.setMethod(element.getMethodName());
|
||||||
}
|
}
|
||||||
BaseCacheUser user = cacheUserService.getCacheUser();
|
BaseCacheUser user = cacheUserService.getCacheUser();
|
||||||
if (null != user) {
|
if (null != user) {
|
||||||
operationLog.setUser(user.setAuthorityList(null));
|
operationLog.setUser(user.setAuthorityList(null));
|
||||||
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
// 提取token头信息 ;
|
// 提取token头信息 ;
|
||||||
operationLog.setToken(request.getHeader(AUTHORIZATION_HEADER))
|
operationLog.setToken(request.getHeader(AUTHORIZATION_HEADER))
|
||||||
.setUrl(request.getMethod() + "." + request.getRequestURI());
|
.setUrl(request.getMethod() + "." + request.getRequestURI());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
operationLog.setId(PropertyUtils.getSnowflakeId())
|
operationLog.setId(PropertyUtils.getSnowflakeId())
|
||||||
.setTransactionId(Optional.ofNullable(operationLog.getTransactionId()).orElseGet(() -> MDC.get(CommonConstants.TRANSACTION_ID)))
|
.setTransactionId(Optional.ofNullable(operationLog.getTransactionId()).orElseGet(() -> MDC.get(CommonConstants.TRANSACTION_ID)))
|
||||||
.setServiceName(serviceName);
|
.setServiceName(serviceName);
|
||||||
kafkaProducer.send(JsonUtils.objectToJson(operationLog));
|
kafkaProducer.send(JsonUtils.objectToJson(operationLog));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info(ExceptionUtil.stacktraceToString(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#spring.task.execution.pool <20>̳߳<DFB3><CCB3><EFBFBD><EFBFBD><EFBFBD>
|
#spring.task.execution.pool <20>̳߳<DFB3><CCB3><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
async.thead.pool.coreSize=200
|
async.thead.pool.coreSize=50
|
||||||
async.thead.pool.maxSize=1000
|
async.thead.pool.maxSize=200
|
||||||
async.thead.pool.queueCapaciry=100
|
async.thead.pool.queueCapaciry=600
|
||||||
async.thead.pool.keepALive=1000
|
async.thead.pool.keepALive=60
|
||||||
async.thead.pool.threadNamePrefix=ebtp-thread
|
async.thead.pool.threadNamePrefix=ebtp-thread
|
@ -6,13 +6,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.chinaunicom.ebtp</groupId>
|
<groupId>com.chinaunicom.ebtp</groupId>
|
||||||
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
||||||
<artifactId>uboot-core</artifactId>
|
<artifactId>uboot-core</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
<name>uboot-core</name>
|
<name>uboot-core</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
<groupId>com.chinaunicom.mall.ebtp</groupId>
|
||||||
<artifactId>uboot-common</artifactId>
|
<artifactId>uboot-common</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
Reference in New Issue
Block a user