Commit 34e69d74 authored by 张辰's avatar 张辰

trace id

parent 2121adca
......@@ -8,11 +8,14 @@ import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.theme.*;
import com.tanpu.community.api.beans.resp.CreateThemeResp;
import com.tanpu.community.api.beans.resp.ThemeListResp;
import com.tanpu.community.feign.community.FeignClientForCommunity;
import com.tanpu.community.manager.ThemeManager;
import com.tanpu.community.service.TraceTestService;
import com.tanpu.community.util.HttpServletHelper;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -30,6 +33,9 @@ public class ThemeController {
private UserHolder userHolder;
@Resource
private HttpServletHelper httpServletHelper;
@Autowired
private TraceTestService traceTestService;
@AuthLogin
@ApiOperation("发表主题")
......@@ -138,4 +144,10 @@ public class ThemeController {
return CommonResp.success();
}
@PostMapping(value = "/testTrace")
@ResponseBody
public CommonResp<Void> testTrace() {
traceTestService.testTraceId();
return CommonResp.success();
}
}
......@@ -5,6 +5,7 @@ import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedSave4NewCommReq;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
@Slf4j
@Component
......@@ -20,6 +21,12 @@ public class FeignBackClientForCommunity implements FallbackFactory<FeignClientF
return null;
}
@Override
public CommonResp testTraceId(@RequestParam("no") String no) {
log.error("请求信息", throwable);
log.error("FeignBackClientForCommunity.testTraceId-测试traceId:{}", no);
return null;
}
};
}
}
......@@ -4,7 +4,9 @@ import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedSave4NewCommReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(value = "service-community", contextId = "community", fallbackFactory = FeignBackClientForCommunity.class, url = "http://tp-tamp-community-svc", path = "/community")
// @FeignClient(value = "service-community", contextId = "community", fallbackFactory = FeignBackClientForCommunity.class, url = "http://127.0.0.1:8202/community")
......@@ -15,4 +17,9 @@ public interface FeignClientForCommunity {
@PostMapping("/newsFeed/save4NewComm")
CommonResp saveNewsFeed4NewComm(NewsFeedSave4NewCommReq req);
/**
* 测试用 traceId
*/
@GetMapping("/newsFeed/testTraceId")
CommonResp testTraceId(@RequestParam("no") String no);
}
package com.tanpu.community.service;
import com.tanpu.community.feign.community.FeignClientForCommunity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.instrument.async.LazyTraceAsyncTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.concurrent.atomic.AtomicInteger;
@Service
@Slf4j
public class TraceTestService {
@Autowired
private BeanFactory beanFactory;
@Autowired
private FeignClientForCommunity feignClientForCommunity;
private LazyTraceAsyncTaskExecutor executor;
private AtomicInteger count;
@PostConstruct
private void init() {
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
pool.setMaxPoolSize(3);
pool.setCorePoolSize(1);
pool.setKeepAliveSeconds(3600);
pool.initialize();
executor = new LazyTraceAsyncTaskExecutor(beanFactory, pool);
count = new AtomicInteger(0);
}
public void testTraceId() {
Integer c = count.incrementAndGet();
log.info("parent count is " + c);
for (int i = 1; i <= 3; i++) {
int subCount = i;
executor.submit(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
log.info("child count is " + c + "-" + subCount);
feignClientForCommunity.testTraceId("" + c + "-" + subCount);
} catch (Exception e) {
}
}
});
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment