Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈文顺
discovery
Commits
600333aa
Commit
600333aa
authored
Feb 02, 2019
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正Hystrix上下文丢失的Bug
parent
7d6ee9f6
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
14 deletions
+57
-14
discovery-plugin-strategy-starter-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/gateway/context/GatewayStrategyContext.java
+1
-1
discovery-plugin-strategy-starter-service/src/main/java/com/nepxion/discovery/plugin/strategy/service/context/RestStrategyContext.java
+1
-1
discovery-plugin-strategy-starter-service/src/main/java/com/nepxion/discovery/plugin/strategy/service/context/RpcStrategyContext.java
+1
-1
discovery-plugin-strategy-starter-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/zuul/context/ZuulStrategyContext.java
+1
-1
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/DiscoveryApplicationA1.java
+1
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/AFeignImpl.java
+10
-10
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/hystrix/HystrixService.java
+42
-0
No files found.
discovery-plugin-strategy-starter-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/gateway/context/GatewayStrategyContext.java
View file @
600333aa
...
...
@@ -16,7 +16,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import
org.springframework.web.server.ServerWebExchange
;
public
class
GatewayStrategyContext
{
private
static
final
ThreadLocal
<
GatewayStrategyContext
>
THREAD_LOCAL
=
new
Inheritable
ThreadLocal
<
GatewayStrategyContext
>()
{
private
static
final
ThreadLocal
<
GatewayStrategyContext
>
THREAD_LOCAL
=
new
ThreadLocal
<
GatewayStrategyContext
>()
{
@Override
protected
GatewayStrategyContext
initialValue
()
{
return
new
GatewayStrategyContext
();
...
...
discovery-plugin-strategy-starter-service/src/main/java/com/nepxion/discovery/plugin/strategy/service/context/RestStrategyContext.java
View file @
600333aa
...
...
@@ -16,7 +16,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import
org.springframework.web.context.request.RequestAttributes
;
public
class
RestStrategyContext
{
private
static
final
ThreadLocal
<
RestStrategyContext
>
THREAD_LOCAL
=
new
Inheritable
ThreadLocal
<
RestStrategyContext
>()
{
private
static
final
ThreadLocal
<
RestStrategyContext
>
THREAD_LOCAL
=
new
ThreadLocal
<
RestStrategyContext
>()
{
@Override
protected
RestStrategyContext
initialValue
()
{
return
new
RestStrategyContext
();
...
...
discovery-plugin-strategy-starter-service/src/main/java/com/nepxion/discovery/plugin/strategy/service/context/RpcStrategyContext.java
View file @
600333aa
...
...
@@ -19,7 +19,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import
org.apache.commons.lang3.builder.ToStringStyle
;
public
class
RpcStrategyContext
{
private
static
final
ThreadLocal
<
RpcStrategyContext
>
THREAD_LOCAL
=
new
Inheritable
ThreadLocal
<
RpcStrategyContext
>()
{
private
static
final
ThreadLocal
<
RpcStrategyContext
>
THREAD_LOCAL
=
new
ThreadLocal
<
RpcStrategyContext
>()
{
@Override
protected
RpcStrategyContext
initialValue
()
{
return
new
RpcStrategyContext
();
...
...
discovery-plugin-strategy-starter-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/zuul/context/ZuulStrategyContext.java
View file @
600333aa
...
...
@@ -18,7 +18,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import
org.apache.commons.lang3.builder.ToStringStyle
;
public
class
ZuulStrategyContext
{
private
static
final
ThreadLocal
<
ZuulStrategyContext
>
THREAD_LOCAL
=
new
Inheritable
ThreadLocal
<
ZuulStrategyContext
>()
{
private
static
final
ThreadLocal
<
ZuulStrategyContext
>
THREAD_LOCAL
=
new
ThreadLocal
<
ZuulStrategyContext
>()
{
@Override
protected
ZuulStrategyContext
initialValue
()
{
return
new
ZuulStrategyContext
();
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/DiscoveryApplicationA1.java
View file @
600333aa
...
...
@@ -30,6 +30,7 @@ import com.nepxion.discovery.plugin.strategy.service.aop.RestTemplateStrategyInt
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
// Hystrix测试
// @EnableCircuitBreaker
public
class
DiscoveryApplicationA1
{
public
static
void
main
(
String
[]
args
)
{
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/AFeignImpl.java
View file @
600333aa
...
...
@@ -26,9 +26,18 @@ public class AFeignImpl extends AbstractFeignImpl implements AFeign {
@Autowired
private
BFeign
bFeign
;
// Hystrix测试
// @Autowired
// private HystrixService hystrixService;
@Override
// @HystrixCommand(fallbackMethod = "fallback", commandProperties = { @HystrixProperty(name = "execution.isolation.strategy", value = "THREAD") })
public
String
invoke
(
@RequestBody
String
value
)
{
// LOG.info("---------- 主方法里获取上下文 RequestContextHolder.getRequestAttributes():{}", RequestContextHolder.getRequestAttributes());
// LOG.info("---------- 主方法里获取上下文 RestStrategyContext.getCurrentContext().getRequestAttributes():{}", RestStrategyContext.getCurrentContext().getRequestAttributes());
// LOG.info("---------- 主方法里获取Token:{}", ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("token"));
// hystrixService.invokeHystrix(value);
value
=
doInvoke
(
value
);
value
=
bFeign
.
invoke
(
value
);
...
...
@@ -36,12 +45,4 @@ public class AFeignImpl extends AbstractFeignImpl implements AFeign {
return
value
;
}
/*public String fallback(String value, Throwable e) {
if (e != null) {
LOG.error("Fallback error", e);
}
return "Fallback by Hystrix";
}*/
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/hystrix/HystrixService.java
0 → 100644
View file @
600333aa
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
hystrix
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
com.nepxion.discovery.plugin.strategy.service.context.RestStrategyContext
;
@Service
public
class
HystrixService
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
HystrixService
.
class
);
// Hystrix测试
// @HystrixCommand(fallbackMethod = "invokeFallback", commandProperties = { @HystrixProperty(name = "execution.isolation.strategy", value = "THREAD") })
public
String
invokeHystrix
(
String
value
)
{
LOG
.
info
(
"---------- 熔断方法里获取上下文 RestStrategyContext.getCurrentContext().getRequestAttributes():{}"
,
RestStrategyContext
.
getCurrentContext
().
getRequestAttributes
());
LOG
.
info
(
"---------- 熔断方法里获取Token:{}"
,
((
ServletRequestAttributes
)
RestStrategyContext
.
getCurrentContext
().
getRequestAttributes
()).
getRequest
().
getHeader
(
"token"
));
return
"Invoke Hystrix"
;
}
public
String
invokeFallback
(
String
value
,
Throwable
e
)
{
LOG
.
info
(
"---------- 快速失败方法里获取上下文 RestStrategyContext.getCurrentContext().getRequestAttributes():{}"
,
RestStrategyContext
.
getCurrentContext
().
getRequestAttributes
());
if
(
e
!=
null
)
{
LOG
.
error
(
"Fallback error"
,
e
);
}
return
"Fallback by Hystrix"
;
}
}
\ No newline at end of file
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