v2.1.1 kafka日志发送改为异步,添加事务排除,添加try catch异常拦截,修改异步线程池参数

This commit is contained in:
fuqingji
2022-03-14 08:54:11 +08:00
parent 7eaec0ffc1
commit af03c1cac5
9 changed files with 59 additions and 48 deletions

View File

@ -7,13 +7,13 @@
<parent>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../mall-ebtp-cloud-parent</relativePath>
</parent>
<groupId>com.chinaunicom.ebtp</groupId>
<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>

View File

@ -8,13 +8,13 @@
<parent>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../mall-ebtp-cloud-parent</relativePath>
</parent>
<groupId>com.chinaunicom.ebtp</groupId>
<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>
<dependencies>

View File

@ -7,12 +7,12 @@
<parent>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
</parent>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>mall-ebtp-cloud-parent</name>
@ -21,22 +21,22 @@
<dependency>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-jpa-starter</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-kafka-starter</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.chinaunicom.mall.ebtp</groupId>
<artifactId>uboot-common</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.chinaunicom.mall.ebtp</groupId>
<artifactId>uboot-core</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -13,7 +13,7 @@
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>mall-ebtp-cloud</name>

View File

@ -6,13 +6,13 @@
<parent>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../mall-ebtp-cloud-parent</relativePath>
</parent>
<groupId>com.chinaunicom.mall.ebtp</groupId>
<artifactId>uboot-common</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<name>uboot-common</name>
<dependencies>

View File

@ -3,6 +3,7 @@ package com.chinaunicom.mall.ebtp.common.log.producer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
/**
@ -20,7 +21,7 @@ public class OperationLogKafkaProducer {
@Autowired
private KafkaTemplate<String, String> kafkaTemplate;
@Async
public void send(String message) {
kafkaTemplate.send(TOPIC, message)
.addCallback(success -> {

View File

@ -1,6 +1,7 @@
package com.chinaunicom.mall.ebtp.common.log.service.impl;
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.service.IBaseCacheUserService;
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.JsonUtils;
import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
@ -29,6 +33,8 @@ import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.
* @author f
*/
@Service
@Slf4j
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class OperationLogServiceImpl implements OperationLogService {
@Autowired
@ -43,6 +49,7 @@ public class OperationLogServiceImpl implements OperationLogService {
@Override
public void addOperationLog(OperationLog operationLog) {
try {
if (operationLog.getMethod() == null) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (int i = 1; i < stackTrace.length; i++) {
@ -75,6 +82,9 @@ public class OperationLogServiceImpl implements OperationLogService {
.setTransactionId(Optional.ofNullable(operationLog.getTransactionId()).orElseGet(() -> MDC.get(CommonConstants.TRANSACTION_ID)))
.setServiceName(serviceName);
kafkaProducer.send(JsonUtils.objectToJson(operationLog));
} catch (Exception e) {
log.info(ExceptionUtil.stacktraceToString(e));
}
}

View File

@ -1,7 +1,7 @@
#spring.task.execution.pool <20>̳߳<DFB3><CCB3><EFBFBD><EFBFBD><EFBFBD>
async.thead.pool.coreSize=200
async.thead.pool.maxSize=1000
async.thead.pool.queueCapaciry=100
async.thead.pool.keepALive=1000
async.thead.pool.coreSize=50
async.thead.pool.maxSize=200
async.thead.pool.queueCapaciry=600
async.thead.pool.keepALive=60
async.thead.pool.threadNamePrefix=ebtp-thread

View File

@ -6,13 +6,13 @@
<parent>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../mall-ebtp-cloud-parent</relativePath>
</parent>
<groupId>com.chinaunicom.mall.ebtp</groupId>
<artifactId>uboot-core</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<name>uboot-core</name>
<dependencies>
@ -20,7 +20,7 @@
<dependency>
<groupId>com.chinaunicom.mall.ebtp</groupId>
<artifactId>uboot-common</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
</dependency>
<dependency>