Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
34e69d74
Commit
34e69d74
authored
Oct 09, 2021
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trace id
parent
2121adca
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
0 deletions
+86
-0
ThemeController.java
.../java/com/tanpu/community/controller/ThemeController.java
+12
-0
FeignBackClientForCommunity.java
...ommunity/feign/community/FeignBackClientForCommunity.java
+7
-0
FeignClientForCommunity.java
...pu/community/feign/community/FeignClientForCommunity.java
+7
-0
TraceTestService.java
...in/java/com/tanpu/community/service/TraceTestService.java
+60
-0
No files found.
community-service/src/main/java/com/tanpu/community/controller/ThemeController.java
View file @
34e69d74
...
...
@@ -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
();
}
}
community-service/src/main/java/com/tanpu/community/feign/community/FeignBackClientForCommunity.java
View file @
34e69d74
...
...
@@ -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
;
}
};
}
}
community-service/src/main/java/com/tanpu/community/feign/community/FeignClientForCommunity.java
View file @
34e69d74
...
...
@@ -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
);
}
community-service/src/main/java/com/tanpu/community/service/TraceTestService.java
0 → 100644
View file @
34e69d74
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
)
{
}
}
});
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment