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
cb012f99
Commit
cb012f99
authored
Mar 22, 2019
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构Sentinel
parent
26833aeb
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
202 additions
and
54 deletions
+202
-54
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/DiscoveryApplicationA1.java
+5
-6
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/AFeign.java
+4
-1
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/BFeign.java
+4
-1
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/CFeign.java
+4
-1
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/ARestImpl.java
+19
-1
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/BRestImpl.java
+19
-1
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/CRestImpl.java
+19
-1
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MyAFeignFallbackHandler.java
+27
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MyBFeignFallbackHandler.java
+27
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MyCFeignFallbackHandler.java
+27
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MyRestTemplateBlockHandler.java
+11
-5
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MyRestTemplateFallbackHanlder.java
+22
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MySentinelFlowRuleParser.java
+1
-1
discovery-springcloud-example-service/src/main/resources/application-a1.properties
+0
-4
discovery-springcloud-example-service/src/main/resources/application-a2.properties
+0
-4
discovery-springcloud-example-service/src/main/resources/application-b1.properties
+0
-4
discovery-springcloud-example-service/src/main/resources/application-b2.properties
+0
-4
discovery-springcloud-example-service/src/main/resources/application-c1.properties
+0
-4
discovery-springcloud-example-service/src/main/resources/application-c2.properties
+0
-4
discovery-springcloud-example-service/src/main/resources/application-c3.properties
+0
-4
discovery-springcloud-example-service/src/main/resources/bootstrap.properties
+12
-7
discovery-springcloud-example-service/src/main/resources/sentinel.json
+1
-1
No files found.
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/DiscoveryApplicationA1.java
View file @
cb012f99
...
@@ -8,6 +8,7 @@ package com.nepxion.discovery.plugin.example.service;
...
@@ -8,6 +8,7 @@ package com.nepxion.discovery.plugin.example.service;
* @author Haojun Ren
* @author Haojun Ren
* @version 1.0
* @version 1.0
*/
*/
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
...
@@ -22,9 +23,10 @@ import com.nepxion.discovery.plugin.example.service.impl.MyDiscoveryEnabledStrat
...
@@ -22,9 +23,10 @@ import com.nepxion.discovery.plugin.example.service.impl.MyDiscoveryEnabledStrat
import
com.nepxion.discovery.plugin.example.service.impl.MyDiscoveryListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyDiscoveryListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyLoadBalanceListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyLoadBalanceListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyRegisterListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MyRegisterListener
;
import
com.nepxion.discovery.plugin.example.service.impl.MySentinelExceptionHandler
;
import
com.nepxion.discovery.plugin.example.service.impl.MySentinelFlowRuleParser
;
import
com.nepxion.discovery.plugin.example.service.impl.MySubscriber
;
import
com.nepxion.discovery.plugin.example.service.impl.MySubscriber
;
import
com.nepxion.discovery.plugin.example.service.sentinel.MyRestTemplateBlockHandler
;
import
com.nepxion.discovery.plugin.example.service.sentinel.MyRestTemplateFallbackHanlder
;
import
com.nepxion.discovery.plugin.example.service.sentinel.MySentinelFlowRuleParser
;
import
com.nepxion.discovery.plugin.strategy.service.aop.RestTemplateStrategyInterceptor
;
import
com.nepxion.discovery.plugin.strategy.service.aop.RestTemplateStrategyInterceptor
;
@SpringBootApplication
@SpringBootApplication
...
@@ -39,12 +41,9 @@ public class DiscoveryApplicationA1 {
...
@@ -39,12 +41,9 @@ public class DiscoveryApplicationA1 {
new
SpringApplicationBuilder
(
DiscoveryApplicationA1
.
class
).
run
(
args
);
new
SpringApplicationBuilder
(
DiscoveryApplicationA1
.
class
).
run
(
args
);
}
}
// @SentinelDataSource("spring.cloud.sentinel.datasource")
// protected ReadableDataSource dataSource;
@Bean
@Bean
@LoadBalanced
@LoadBalanced
@SentinelRestTemplate
(
blockHandler
=
"handle
Exception"
,
blockHandlerClass
=
MySentinelExceptionHandl
er
.
class
)
@SentinelRestTemplate
(
blockHandler
=
"handle
Block"
,
blockHandlerClass
=
MyRestTemplateBlockHandler
.
class
,
fallback
=
"handleFallback"
,
fallbackClass
=
MyRestTemplateFallbackHanld
er
.
class
)
public
RestTemplate
restTemplate
(
@Autowired
(
required
=
false
)
RestTemplateStrategyInterceptor
restTemplateStrategyInterceptor
)
{
public
RestTemplate
restTemplate
(
@Autowired
(
required
=
false
)
RestTemplateStrategyInterceptor
restTemplateStrategyInterceptor
)
{
RestTemplate
restTemplate
=
new
RestTemplate
();
RestTemplate
restTemplate
=
new
RestTemplate
();
if
(
restTemplateStrategyInterceptor
!=
null
)
{
if
(
restTemplateStrategyInterceptor
!=
null
)
{
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/AFeign.java
View file @
cb012f99
...
@@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"discovery-springcloud-example-a"
)
import
com.nepxion.discovery.plugin.example.service.sentinel.MyAFeignFallbackHandler
;
@FeignClient
(
value
=
"discovery-springcloud-example-a"
,
fallback
=
MyAFeignFallbackHandler
.
class
)
// Context-patch一旦被设置,在Feign也要带上context-path,外部Postman调用网关或者服务路径也要带context-path
// Context-patch一旦被设置,在Feign也要带上context-path,外部Postman调用网关或者服务路径也要带context-path
// @FeignClient(value = "discovery-springcloud-example-a", path = "/nepxion")
// @FeignClient(value = "discovery-springcloud-example-a/nepxion")
// @FeignClient(value = "discovery-springcloud-example-a/nepxion")
public
interface
AFeign
{
public
interface
AFeign
{
@RequestMapping
(
path
=
"/invoke"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/invoke"
,
method
=
RequestMethod
.
POST
)
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/BFeign.java
View file @
cb012f99
...
@@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"discovery-springcloud-example-b"
)
import
com.nepxion.discovery.plugin.example.service.sentinel.MyBFeignFallbackHandler
;
@FeignClient
(
value
=
"discovery-springcloud-example-b"
,
fallback
=
MyBFeignFallbackHandler
.
class
)
// Context-patch一旦被设置,在Feign也要带上context-path,外部Postman调用网关或者服务路径也要带context-path
// Context-patch一旦被设置,在Feign也要带上context-path,外部Postman调用网关或者服务路径也要带context-path
// @FeignClient(value = "discovery-springcloud-example-b", path = "/nepxion")
// @FeignClient(value = "discovery-springcloud-example-b/nepxion")
// @FeignClient(value = "discovery-springcloud-example-b/nepxion")
public
interface
BFeign
{
public
interface
BFeign
{
@RequestMapping
(
path
=
"/invoke"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/invoke"
,
method
=
RequestMethod
.
POST
)
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/CFeign.java
View file @
cb012f99
...
@@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"discovery-springcloud-example-c"
)
import
com.nepxion.discovery.plugin.example.service.sentinel.MyCFeignFallbackHandler
;
@FeignClient
(
value
=
"discovery-springcloud-example-c"
,
fallback
=
MyCFeignFallbackHandler
.
class
)
// Context-patch一旦被设置,在Feign也要带上context-path,外部Postman调用网关或者服务路径也要带context-path
// Context-patch一旦被设置,在Feign也要带上context-path,外部Postman调用网关或者服务路径也要带context-path
// @FeignClient(value = "discovery-springcloud-example-c", path = "/nepxion")
// @FeignClient(value = "discovery-springcloud-example-c/nepxion")
// @FeignClient(value = "discovery-springcloud-example-c/nepxion")
public
interface
CFeign
{
public
interface
CFeign
{
@RequestMapping
(
path
=
"/invoke"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/invoke"
,
method
=
RequestMethod
.
POST
)
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/ARestImpl.java
View file @
cb012f99
...
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
com.alibaba.csp.sentinel.annotation.SentinelResource
;
import
com.alibaba.csp.sentinel.annotation.SentinelResource
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
@RestController
@RestController
...
@@ -31,7 +32,7 @@ public class ARestImpl extends AbstractRestImpl {
...
@@ -31,7 +32,7 @@ public class ARestImpl extends AbstractRestImpl {
private
RestTemplate
restTemplate
;
private
RestTemplate
restTemplate
;
@RequestMapping
(
path
=
"/rest"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/rest"
,
method
=
RequestMethod
.
POST
)
@SentinelResource
(
"sentinel-resource
"
)
@SentinelResource
(
value
=
"sentinel-resource"
,
blockHandler
=
"handleBlock"
,
fallback
=
"handleFallback
"
)
public
String
rest
(
@RequestBody
String
value
)
{
public
String
rest
(
@RequestBody
String
value
)
{
value
=
doRest
(
value
);
value
=
doRest
(
value
);
value
=
restTemplate
.
postForEntity
(
"http://discovery-springcloud-example-b/rest"
,
value
,
String
.
class
).
getBody
();
value
=
restTemplate
.
postForEntity
(
"http://discovery-springcloud-example-b/rest"
,
value
,
String
.
class
).
getBody
();
...
@@ -45,4 +46,20 @@ public class ARestImpl extends AbstractRestImpl {
...
@@ -45,4 +46,20 @@ public class ARestImpl extends AbstractRestImpl {
public
String
test
(
@RequestBody
String
value
)
{
public
String
test
(
@RequestBody
String
value
)
{
return
value
;
return
value
;
}
}
public
String
handleBlock
(
String
value
,
BlockException
e
)
{
LOG
.
info
(
"Value={}"
,
value
);
LOG
.
info
(
"Sentinel AServer Block Causes"
);
LOG
.
error
(
"Sentinel AServer Block Exception"
,
e
);
LOG
.
info
(
"Sentinel Rule Limit App={}"
,
e
.
getRuleLimitApp
());
return
"Sentinel AServer Block Causes"
;
}
public
String
handleFallback
(
String
value
)
{
LOG
.
info
(
"Value={}"
,
value
);
LOG
.
info
(
"Sentinel AServer Fallback Causes"
);
return
"Sentinel AServer Fallback Causes"
;
}
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/BRestImpl.java
View file @
cb012f99
...
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
com.alibaba.csp.sentinel.annotation.SentinelResource
;
import
com.alibaba.csp.sentinel.annotation.SentinelResource
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
@RestController
@RestController
...
@@ -31,7 +32,7 @@ public class BRestImpl extends AbstractRestImpl {
...
@@ -31,7 +32,7 @@ public class BRestImpl extends AbstractRestImpl {
private
RestTemplate
restTemplate
;
private
RestTemplate
restTemplate
;
@RequestMapping
(
path
=
"/rest"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/rest"
,
method
=
RequestMethod
.
POST
)
@SentinelResource
(
"sentinel-resource
"
)
@SentinelResource
(
value
=
"sentinel-resource"
,
blockHandler
=
"handleBlock"
,
fallback
=
"handleFallback
"
)
public
String
rest
(
@RequestBody
String
value
)
{
public
String
rest
(
@RequestBody
String
value
)
{
value
=
doRest
(
value
);
value
=
doRest
(
value
);
value
=
restTemplate
.
postForEntity
(
"http://discovery-springcloud-example-c/rest"
,
value
,
String
.
class
).
getBody
();
value
=
restTemplate
.
postForEntity
(
"http://discovery-springcloud-example-c/rest"
,
value
,
String
.
class
).
getBody
();
...
@@ -45,4 +46,20 @@ public class BRestImpl extends AbstractRestImpl {
...
@@ -45,4 +46,20 @@ public class BRestImpl extends AbstractRestImpl {
public
String
test
(
@RequestBody
String
value
)
{
public
String
test
(
@RequestBody
String
value
)
{
return
value
;
return
value
;
}
}
public
String
handleBlock
(
String
value
,
BlockException
e
)
{
LOG
.
info
(
"Value={}"
,
value
);
LOG
.
info
(
"Sentinel BServer Block Causes"
);
LOG
.
error
(
"Sentinel BServer Block Exception"
,
e
);
LOG
.
info
(
"Sentinel Rule Limit App={}"
,
e
.
getRuleLimitApp
());
return
"Sentinel BServer Block Causes"
;
}
public
String
handleFallback
(
String
value
)
{
LOG
.
info
(
"Value={}"
,
value
);
LOG
.
info
(
"Sentinel BServer Fallback Causes"
);
return
"Sentinel BServer Fallback Causes"
;
}
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/rest/CRestImpl.java
View file @
cb012f99
...
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
...
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.alibaba.csp.sentinel.annotation.SentinelResource
;
import
com.alibaba.csp.sentinel.annotation.SentinelResource
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
@RestController
@RestController
...
@@ -26,7 +27,7 @@ public class CRestImpl extends AbstractRestImpl {
...
@@ -26,7 +27,7 @@ public class CRestImpl extends AbstractRestImpl {
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
CRestImpl
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
CRestImpl
.
class
);
@RequestMapping
(
path
=
"/rest"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/rest"
,
method
=
RequestMethod
.
POST
)
@SentinelResource
(
"sentinel-resource
"
)
@SentinelResource
(
value
=
"sentinel-resource"
,
blockHandler
=
"handleBlock"
,
fallback
=
"handleFallback
"
)
public
String
rest
(
@RequestBody
String
value
)
{
public
String
rest
(
@RequestBody
String
value
)
{
value
=
doRest
(
value
);
value
=
doRest
(
value
);
...
@@ -39,4 +40,20 @@ public class CRestImpl extends AbstractRestImpl {
...
@@ -39,4 +40,20 @@ public class CRestImpl extends AbstractRestImpl {
public
String
test
(
@RequestBody
String
value
)
{
public
String
test
(
@RequestBody
String
value
)
{
return
value
;
return
value
;
}
}
public
String
handleBlock
(
String
value
,
BlockException
e
)
{
LOG
.
info
(
"Value={}"
,
value
);
LOG
.
info
(
"Sentinel CServer Block Causes"
);
LOG
.
error
(
"Sentinel CServer Block Exception"
,
e
);
LOG
.
info
(
"Sentinel Rule Limit App={}"
,
e
.
getRuleLimitApp
());
return
"Sentinel CServer Block Causes"
;
}
public
String
handleFallback
(
String
value
)
{
LOG
.
info
(
"Value={}"
,
value
);
LOG
.
info
(
"Sentinel CServer Fallback Causes"
);
return
"Sentinel CServer Fallback Causes"
;
}
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MyAFeignFallbackHandler.java
0 → 100644
View file @
cb012f99
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
sentinel
;
/**
* <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
com.nepxion.discovery.plugin.example.service.feign.AFeign
;
public
class
MyAFeignFallbackHandler
implements
AFeign
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MyAFeignFallbackHandler
.
class
);
@Override
public
String
invoke
(
String
value
)
{
LOG
.
info
(
"Value={}"
,
value
);
return
"Sentinel AFeign Client Fallback Causes"
;
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MyBFeignFallbackHandler.java
0 → 100644
View file @
cb012f99
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
sentinel
;
/**
* <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
com.nepxion.discovery.plugin.example.service.feign.BFeign
;
public
class
MyBFeignFallbackHandler
implements
BFeign
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MyBFeignFallbackHandler
.
class
);
@Override
public
String
invoke
(
String
value
)
{
LOG
.
info
(
"Value={}"
,
value
);
return
"Sentinel BFeign Client Fallback Causes"
;
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MyCFeignFallbackHandler.java
0 → 100644
View file @
cb012f99
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
sentinel
;
/**
* <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
com.nepxion.discovery.plugin.example.service.feign.CFeign
;
public
class
MyCFeignFallbackHandler
implements
CFeign
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MyCFeignFallbackHandler
.
class
);
@Override
public
String
invoke
(
String
value
)
{
LOG
.
info
(
"Value={}"
,
value
);
return
"Sentinel CFeign Client Fallback Causes"
;
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/
impl/MySentinelException
Handler.java
→
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/
sentinel/MyRestTemplateBlock
Handler.java
View file @
cb012f99
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
imp
l
;
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
sentine
l
;
/**
/**
* <p>Title: Nepxion Discovery</p>
* <p>Title: Nepxion Discovery</p>
...
@@ -14,10 +14,15 @@ import org.slf4j.LoggerFactory;
...
@@ -14,10 +14,15 @@ import org.slf4j.LoggerFactory;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
public
class
My
SentinelException
Handler
{
public
class
My
RestTemplateBlock
Handler
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
My
SentinelException
Handler
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
My
RestTemplateBlock
Handler
.
class
);
public
static
void
handleException
(
BlockException
e
)
{
public
static
String
handleBlock
(
String
value
,
BlockException
e
)
{
LOG
.
error
(
"Sentinel exception causes"
,
e
);
LOG
.
info
(
"Value={}"
,
value
);
LOG
.
info
(
"Sentinel RestTemplate Client Block Causes"
);
LOG
.
error
(
"Sentinel RestTemplate Client Block Exception"
,
e
);
LOG
.
info
(
"Sentinel Rule Limit App={}"
,
e
.
getRuleLimitApp
());
return
"Sentinel RestTemplate Client Block Causes"
;
}
}
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/sentinel/MyRestTemplateFallbackHanlder.java
0 → 100644
View file @
cb012f99
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
sentinel
;
/**
* <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
;
public
class
MyRestTemplateFallbackHanlder
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MyRestTemplateFallbackHanlder
.
class
);
public
static
void
hanldleFallback
()
{
LOG
.
info
(
"Sentinel RestTemplate Client Fallback Causes"
);
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/
imp
l/MySentinelFlowRuleParser.java
→
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/
sentine
l/MySentinelFlowRuleParser.java
View file @
cb012f99
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
imp
l
;
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
service
.
sentine
l
;
/**
/**
* <p>Title: Nepxion Discovery</p>
* <p>Title: Nepxion Discovery</p>
...
...
discovery-springcloud-example-service/src/main/resources/application-a1.properties
View file @
cb012f99
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
spring.cloud.nacos.discovery.metadata.version
=
1.0
spring.cloud.nacos.discovery.metadata.version
=
1.0
spring.cloud.nacos.discovery.metadata.region
=
dev
spring.cloud.nacos.discovery.metadata.region
=
dev
# Sentinel config
spring.cloud.sentinel.transport.port
=
4100
# Admin config
# Admin config
management.server.port
=
5100
management.server.port
=
5100
\ No newline at end of file
discovery-springcloud-example-service/src/main/resources/application-a2.properties
View file @
cb012f99
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
spring.cloud.nacos.discovery.metadata.version
=
1.1
spring.cloud.nacos.discovery.metadata.version
=
1.1
spring.cloud.nacos.discovery.metadata.region
=
qa
spring.cloud.nacos.discovery.metadata.region
=
qa
# Sentinel config
spring.cloud.sentinel.transport.port
=
4101
# Admin config
# Admin config
management.server.port
=
5101
management.server.port
=
5101
\ No newline at end of file
discovery-springcloud-example-service/src/main/resources/application-b1.properties
View file @
cb012f99
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
spring.cloud.nacos.discovery.metadata.version
=
1.0
spring.cloud.nacos.discovery.metadata.version
=
1.0
spring.cloud.nacos.discovery.metadata.region
=
dev
spring.cloud.nacos.discovery.metadata.region
=
dev
# Sentinel config
spring.cloud.sentinel.transport.port
=
4200
# Admin config
# Admin config
management.server.port
=
5200
management.server.port
=
5200
\ No newline at end of file
discovery-springcloud-example-service/src/main/resources/application-b2.properties
View file @
cb012f99
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
spring.cloud.nacos.discovery.metadata.version
=
1.1
spring.cloud.nacos.discovery.metadata.version
=
1.1
spring.cloud.nacos.discovery.metadata.region
=
qa
spring.cloud.nacos.discovery.metadata.region
=
qa
# Sentinel config
spring.cloud.sentinel.transport.port
=
4201
# Admin config
# Admin config
management.server.port
=
5201
management.server.port
=
5201
\ No newline at end of file
discovery-springcloud-example-service/src/main/resources/application-c1.properties
View file @
cb012f99
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
spring.cloud.nacos.discovery.metadata.version
=
1.0
spring.cloud.nacos.discovery.metadata.version
=
1.0
spring.cloud.nacos.discovery.metadata.region
=
dev
spring.cloud.nacos.discovery.metadata.region
=
dev
# Sentinel config
spring.cloud.sentinel.transport.port
=
4300
# Admin config
# Admin config
management.server.port
=
5300
management.server.port
=
5300
\ No newline at end of file
discovery-springcloud-example-service/src/main/resources/application-c2.properties
View file @
cb012f99
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
spring.cloud.nacos.discovery.metadata.version
=
1.1
spring.cloud.nacos.discovery.metadata.version
=
1.1
spring.cloud.nacos.discovery.metadata.region
=
qa
spring.cloud.nacos.discovery.metadata.region
=
qa
# Sentinel config
spring.cloud.sentinel.transport.port
=
4301
# Admin config
# Admin config
management.server.port
=
5301
management.server.port
=
5301
\ No newline at end of file
discovery-springcloud-example-service/src/main/resources/application-c3.properties
View file @
cb012f99
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
...
@@ -20,8 +20,5 @@ spring.cloud.nacos.discovery.metadata.group=example-service-group
spring.cloud.nacos.discovery.metadata.version
=
1.2
spring.cloud.nacos.discovery.metadata.version
=
1.2
spring.cloud.nacos.discovery.metadata.region
=
qa
spring.cloud.nacos.discovery.metadata.region
=
qa
# Sentinel config
spring.cloud.sentinel.transport.port
=
4302
# Admin config
# Admin config
management.server.port
=
5302
management.server.port
=
5302
\ No newline at end of file
discovery-springcloud-example-service/src/main/resources/bootstrap.properties
View file @
cb012f99
...
@@ -45,14 +45,19 @@ spring.redis.pool.min-idle=0
...
@@ -45,14 +45,19 @@ spring.redis.pool.min-idle=0
# Sentinel config
# Sentinel config
spring.cloud.sentinel.transport.dashboard
=
localhost:8075
spring.cloud.sentinel.transport.dashboard
=
localhost:8075
# spring.cloud.sentinel.datasource.type=file
spring.cloud.sentinel.eager
=
true
# spring.cloud.sentinel.datasource.recommendRefreshMs=3000
# 本地规则方式和远程规则方式不能同时并存,必须两选一。使用时候必须注释掉其中之一,生成环境必须使用远程规则方式
# spring.cloud.sentinel.datasource.bufSize=4056196
# 本地规则方式配置
# spring.cloud.sentinel.datasource.charset=utf-8
spring.cloud.sentinel.datasource.ds1.file.file
=
classpath:sentinel.json
# spring.cloud.sentinel.datasource.converter=mySentinelFlowRuleParser
spring.cloud.sentinel.datasource.ds1.file.data-type
=
json
# spring.cloud.sentinel.datasource.file=sentinel-rule.json
spring.cloud.sentinel.datasource.ds1.file.rule-type
=
flow
# spring.cloud.sentinel.datasource.file=E://sentinel-rule.json
# 远程规则方式配置
# spring.cloud.sentinel.datasource.ds2.apollo.namespace-name=application
# spring.cloud.sentinel.datasource.ds2.apollo.flow-rules-key=example-service-group-${spring.application.name}-sentinel-flow
# spring.cloud.sentinel.datasource.ds2.apollo.rule-type=flow
# Feign和RestTemplate熔断降级限流开关
feign.sentinel.enabled
=
true
feign.sentinel.enabled
=
true
resttemplate.sentinel.enabled
=
true
# Admin config
# Admin config
# 该项只对Consul有效,而且必须配置在bootstrap.properties里,配置在application.properties无效
# 该项只对Consul有效,而且必须配置在bootstrap.properties里,配置在application.properties无效
...
...
discovery-springcloud-example-service/src/main/resources/sentinel
-rule
.json
→
discovery-springcloud-example-service/src/main/resources/sentinel.json
View file @
cb012f99
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
{
{
"resource"
:
"sentinel-resource"
,
"resource"
:
"sentinel-resource"
,
"controlBehavior"
:
0
,
"controlBehavior"
:
0
,
"count"
:
5.0
,
"count"
:
1
,
"grade"
:
1
,
"grade"
:
1
,
"limitApp"
:
"default"
,
"limitApp"
:
"default"
,
"strategy"
:
0
"strategy"
:
0
...
...
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