|
@@ -8,6 +8,7 @@ import com.gis.mapper.FodderMapper;
|
|
|
import com.gis.util.CmdUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.Test;
|
|
|
+import org.slf4j.MDC;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -33,18 +34,35 @@ public class Fd720Listener {
|
|
|
@Autowired
|
|
|
FodderMapper fodderMapper;
|
|
|
|
|
|
+ // 链路id
|
|
|
+ static String traceId;
|
|
|
|
|
|
+ // 多线程处理消息
|
|
|
+ static ExecutorService executor = Executors.newFixedThreadPool(2);
|
|
|
|
|
|
@RabbitHandler
|
|
|
public void getMessage(Long param) {
|
|
|
+ traceId = System.currentTimeMillis()+"";
|
|
|
+ MDC.put("TRACE_ID", traceId);
|
|
|
+
|
|
|
+ log.info("监听消息开始: {}, uuid: {}", param, traceId);
|
|
|
try {
|
|
|
Thread.sleep(300);
|
|
|
} catch (InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- log.warn("run Fd720Listener id: " + param);
|
|
|
- processPano(param);
|
|
|
- log.warn("end Fd720Listener id: "+ param);
|
|
|
+ CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> {
|
|
|
+ MDC.put("TRACE_ID", traceId);
|
|
|
+ log.info("进入多线程: {}", param);
|
|
|
+ processPano(param, traceId);
|
|
|
+ return "多线程正确执行完成";
|
|
|
+ }, executor);
|
|
|
+
|
|
|
+ future2.thenAccept((e) -> {
|
|
|
+ log.info("执行完成结果:{}", e);
|
|
|
+ });
|
|
|
+
|
|
|
+ log.info("监听消息完成: {}, uuid: {}", param, traceId);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -52,9 +70,10 @@ public class Fd720Listener {
|
|
|
* 切图会超时控制
|
|
|
* @param id
|
|
|
*/
|
|
|
- public void processPano(Long id) {
|
|
|
+ public void processPano(Long id, String traceId) {
|
|
|
+ MDC.put("TRACE_ID", traceId);
|
|
|
|
|
|
- log.warn("run processPano : " + id);
|
|
|
+ log.info("切图流程开始 : " + id);
|
|
|
long start = System.currentTimeMillis();
|
|
|
FodderEntity entity = fodderMapper.findById(id);
|
|
|
if (entity == null) {
|
|
@@ -72,6 +91,7 @@ public class Fd720Listener {
|
|
|
Callable<String> call = new Callable<String>() {
|
|
|
@Override
|
|
|
public String call() throws Exception {
|
|
|
+ MDC.put("TRACE_ID", traceId);
|
|
|
CmdUtils.callLine(cmd, 200);
|
|
|
long end = System.currentTimeMillis();
|
|
|
log.info("切图完成耗时: {} s" ,(end-start)/1000);
|
|
@@ -113,40 +133,12 @@ public class Fd720Listener {
|
|
|
} finally {
|
|
|
entity.setUpdateTime(new Date());
|
|
|
fodderMapper.updateByPrimaryKey(entity);
|
|
|
+ log.info("切图流程, 更新数据库完成 : " + id);
|
|
|
}
|
|
|
+ log.info("切图流程结束 : " + id);
|
|
|
}
|
|
|
|
|
|
|
|
|
-// public void cmdPano(Long id) {
|
|
|
-// log.info("start task cmdPano");
|
|
|
-//// FodderEntity entity = fodderMapper.selectByPrimaryKey(id);
|
|
|
-// FodderEntity entity = fodderMapper.findById(id);
|
|
|
-// if (entity == null) {
|
|
|
-// log.error("场景不存在: " + id);
|
|
|
-// // 直接结束,抛异常的话,会造成死循环,产生大量日志,而且队列也跑不下去
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// try {
|
|
|
-//
|
|
|
-// // 切图
|
|
|
-// long start = System.currentTimeMillis();
|
|
|
-// String panoPath = entity.getFilePath();
|
|
|
-// String sceneCode = entity.getSceneCode();
|
|
|
-// String cmd = CmdConstant.PANO_KRPANO + panoPath;
|
|
|
-//// log.info("cmd: " + cmd);
|
|
|
-// CmdUtils.cmdPano(cmd);
|
|
|
-// long end = System.currentTimeMillis();
|
|
|
-// log.info("切图完成耗时: {} s" ,(end-start)/1000);
|
|
|
-// uploadOss(sceneCode);
|
|
|
-// entity.setStatus(3);
|
|
|
-// } catch (Exception e) {
|
|
|
-// entity.setStatus(2);
|
|
|
-// e.printStackTrace();
|
|
|
-// } finally {
|
|
|
-// fodderMapper.updateByPrimaryKey(entity);
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
|
|
|
/**
|
|
|
* 上传切图目录
|