0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

  sentinel即哨兵,相比hystrix断路器而言,它的功能更丰富。hystrix仅支持熔断,当服务消费方调用提供方发现异常后,进入熔断;sentinel不仅支持异常熔断,也支持响应超时熔断,另外还支持限流,以及针对网关的熔断和限流。此外,它还有过载处理、监控控制台(Sentinel Dashboard)等。hystrix作为组件集成到微服务中,sentinel也是如此,但它的控制台需要独立部署。

  先下载Sentinel Dashboard(下载地址https://github.com/alibaba/Sentinel/releases),目前最新版本是1.6.3,下载到本地(我的是E盘download目录下)后启动jar包:

C:\Users\wulf>e:

E:\>cd download

E:\download>java -jar sentinel-dashboard-1.6.3.jar
INFO: log base dir is: C:\Users\wulf\logs\csp\
INFO: log name use pid is: false . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE) 2019-08-23 09:08:38.125 INFO 42064 --- [ main] c.a.c.s.dashboard.DashboardApplication : Starting DashboardApplication on wulf00 with PID 42064 (E:\download\sentinel-dashboard-1.6.3.jar started by wulf in E:\download)
2019-08-23 09:08:38.137 INFO 42064 --- [ main] c.a.c.s.dashboard.DashboardApplication : No active profile set, falling back to default profiles: default
2019-08-23 09:08:38.263 INFO 42064 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c629d6e: startup date [Fri Aug 23 09:08:38 CST 2019]; root of context hierarchy
2019-08-23 09:08:41.446 ERROR 42064 --- [ main] o.a.catalina.core.AprLifecycleListener : An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]
2019-08-23 09:08:41.787 INFO 42064 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-08-23 09:08:41.817 ERROR 42064 --- [ main] o.a.catalina.core.AprLifecycleListener : An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]
2019-08-23 09:08:41.859 INFO 42064 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-23 09:08:41.861 INFO 42064 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
2019-08-23 09:08:41.887 ERROR 42064 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]
2019-08-23 09:08:42.037 INFO 42064 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-23 09:08:42.039 INFO 42064 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3777 ms
2019-08-23 09:08:42.163 INFO 42064 --- [ost-startStop-1] c.a.c.s.dashboard.config.WebConfig : Sentinel servlet CommonFilter registered
2019-08-23 09:08:42.288 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-08-23 09:08:42.291 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-08-23 09:08:42.292 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-08-23 09:08:42.293 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-08-23 09:08:42.295 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'authenticationFilter' to urls: [/*]
2019-08-23 09:08:42.296 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'sentinelFilter' to urls: [/*]
2019-08-23 09:08:42.296 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2019-08-23 09:08:43.660 INFO 42064 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-08-23 09:08:43.930 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c629d6e: startup date [Fri Aug 23 09:08:38 CST 2019]; root of context hierarchy
2019-08-23 09:08:44.060 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/registry/machine],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<?> com.alibaba.csp.sentinel.dashboard.controller.MachineRegistryController.receiveHeartBeat(java.lang.String,java.lang.Integer,java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.Integer)
2019-08-23 09:08:44.067 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/auth/logout],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result com.alibaba.csp.sentinel.dashboard.controller.AuthController.logout(javax.servlet.http.HttpServletRequest)
2019-08-23 09:08:44.068 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/auth/login],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result com.alibaba.csp.sentinel.dashboard.controller.AuthController.login(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String)
2019-08-23 09:08:44.083 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v1/flow/delete.json],methods=[DELETE]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1.delete(javax.servlet.http.HttpServletRequest,java.lang.Long)
2019-08-23 09:08:44.084 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v1/flow/rules],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1.apiQueryMachineRules(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer)
2019-08-23 09:08:44.085 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v1/flow/rule],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1.apiAddFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity)
2019-08-23 09:08:44.088 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v1/flow/save.json],methods=[PUT]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1.updateIfNotNull(javax.servlet.http.HttpServletRequest,java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.Integer,java.lang.Double,java.lang.Integer,java.lang.String,java.lang.Integer,java.lang.Integer,java.lang.Integer)
2019-08-23 09:08:44.094 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/flow/rules],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2.apiQueryMachineRules(javax.servlet.http.HttpServletRequest,java.lang.String)
2019-08-23 09:08:44.095 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/flow/rule/{id}],methods=[PUT]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2.apiUpdateFlowRule(javax.servlet.http.HttpServletRequest,java.lang.Long,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity)
2019-08-23 09:08:44.097 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/flow/rule],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2.apiAddFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity)
2019-08-23 09:08:44.099 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/flow/rule/{id}],methods=[DELETE]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2.apiDeleteRule(javax.servlet.http.HttpServletRequest,java.lang.Long)
2019-08-23 09:08:44.106 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/app/{app}/machine/remove.json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.String> com.alibaba.csp.sentinel.dashboard.controller.AppController.removeMachineById(java.lang.String,java.lang.String,int)
2019-08-23 09:08:44.108 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/app/{app}/machines.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.vo.MachineInfoVo>> com.alibaba.csp.sentinel.dashboard.controller.AppController.getMachinesByApp(java.lang.String)
2019-08-23 09:08:44.109 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/app/names.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<java.lang.String>> com.alibaba.csp.sentinel.dashboard.controller.AppController.queryApps(javax.servlet.http.HttpServletRequest)
2019-08-23 09:08:44.110 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/app/briefinfos.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.discovery.AppInfo>> com.alibaba.csp.sentinel.dashboard.controller.AppController.queryAppInfos(javax.servlet.http.HttpServletRequest)
2019-08-23 09:08:44.114 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/demo/loop],produces=[application/json]}" onto public java.lang.String com.alibaba.csp.sentinel.dashboard.controller.DemoController.loop(java.lang.String,int) throws com.alibaba.csp.sentinel.slots.block.BlockException
2019-08-23 09:08:44.115 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/demo/link],produces=[application/json]}" onto public java.lang.String com.alibaba.csp.sentinel.dashboard.controller.DemoController.link() throws com.alibaba.csp.sentinel.slots.block.BlockException
2019-08-23 09:08:44.118 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/demo/greeting],produces=[application/json]}" onto public java.lang.String com.alibaba.csp.sentinel.dashboard.controller.DemoController.greeting()
2019-08-23 09:08:44.122 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/demo/slow],produces=[application/json]}" onto public java.lang.String com.alibaba.csp.sentinel.dashboard.controller.DemoController.slow(java.lang.String,int) throws com.alibaba.csp.sentinel.slots.block.BlockException
2019-08-23 09:08:44.124 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/resource/machineResource.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.vo.ResourceVo>> com.alibaba.csp.sentinel.dashboard.controller.ResourceController.fetchResourceChainListOfMachine(java.lang.String,java.lang.Integer,java.lang.String,java.lang.String)
2019-08-23 09:08:44.128 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/assign/all_server/{app}],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterAssignController.apiAssignAllClusterServersOfApp(java.lang.String,com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppFullAssignRequest)
2019-08-23 09:08:44.129 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/assign/unbind_server/{app}],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterAssignController.apiUnbindClusterServersOfApp(java.lang.String,java.util.Set<java.lang.String>)
2019-08-23 09:08:44.131 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/assign/single_server/{app}],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterAssignController.apiAssignSingleClusterServersOfApp(java.lang.String,com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppSingleServerAssignRequest)
2019-08-23 09:08:44.136 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/api/delete.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayApiController.deleteApi(javax.servlet.http.HttpServletRequest,java.lang.Long)
2019-08-23 09:08:44.137 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/api/list.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity>> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayApiController.queryApis(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer)
2019-08-23 09:08:44.140 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/api/new.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayApiController.addApi(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.domain.vo.gateway.api.AddApiReqVo)
2019-08-23 09:08:44.142 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/api/save.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayApiController.updateApi(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.domain.vo.gateway.api.UpdateApiReqVo)
2019-08-23 09:08:44.147 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/paramFlow/rules],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.ParamFlowRuleController.apiQueryAllRulesForMachine(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer)
2019-08-23 09:08:44.149 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/paramFlow/rule],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.ParamFlowRuleController.apiAddParamFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity)
2019-08-23 09:08:44.151 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/paramFlow/rule/{id}],methods=[PUT]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.ParamFlowRuleController.apiUpdateParamFlowRule(javax.servlet.http.HttpServletRequest,java.lang.Long,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity)
2019-08-23 09:08:44.153 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/paramFlow/rule/{id}],methods=[DELETE]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.ParamFlowRuleController.apiDeleteRule(javax.servlet.http.HttpServletRequest,java.lang.Long)
2019-08-23 09:08:44.157 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/authority/rules],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.AuthorityRuleController.apiQueryAllRulesForMachine(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer)
2019-08-23 09:08:44.159 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/authority/rule],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.AuthorityRuleController.apiAddAuthorityRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity)
2019-08-23 09:08:44.164 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/authority/rule/{id}],methods=[PUT]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.AuthorityRuleController.apiUpdateParamFlowRule(javax.servlet.http.HttpServletRequest,java.lang.Long,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity)
2019-08-23 09:08:44.168 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/authority/rule/{id}],methods=[DELETE]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.AuthorityRuleController.apiDeleteRule(javax.servlet.http.HttpServletRequest,java.lang.Long)
2019-08-23 09:08:44.171 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/flow/new.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayFlowRuleController.addFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.domain.vo.gateway.rule.AddFlowRuleReqVo)
2019-08-23 09:08:44.172 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/flow/list.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayFlowRuleController.queryFlowRules(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer)
2019-08-23 09:08:44.173 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/flow/delete.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayFlowRuleController.deleteFlowRule(javax.servlet.http.HttpServletRequest,java.lang.Long)
2019-08-23 09:08:44.174 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/flow/save.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayFlowRuleController.updateFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.domain.vo.gateway.rule.UpdateFlowRuleReqVo)
2019-08-23 09:08:44.178 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/server_state/{app}],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO>> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiGetClusterServerStateOfApp(java.lang.String)
2019-08-23 09:08:44.180 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/config/modify_single],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Boolean> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiModifyClusterConfig(java.lang.String)
2019-08-23 09:08:44.181 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/state/{app}],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO>> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiGetClusterStateOfApp(java.lang.String)
2019-08-23 09:08:44.185 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/client_state/{app}],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterClientStateWrapVO>> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiGetClusterClientStateOfApp(java.lang.String)
2019-08-23 09:08:44.188 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/state_single],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiGetClusterState(java.lang.String,java.lang.String,java.lang.Integer)
2019-08-23 09:08:44.191 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/metric/queryByAppAndResource.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<?> com.alibaba.csp.sentinel.dashboard.controller.MetricController.queryByAppAndResource(java.lang.String,java.lang.String,java.lang.Long,java.lang.Long)
2019-08-23 09:08:44.192 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/metric/queryTopResourceMetric.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<?> com.alibaba.csp.sentinel.dashboard.controller.MetricController.queryTopResourceMetric(java.lang.String,java.lang.Integer,java.lang.Integer,java.lang.Boolean,java.lang.Long,java.lang.Long,java.lang.String)
2019-08-23 09:08:44.194 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/degrade/new.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.DegradeController.add(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer,java.lang.String,java.lang.String,java.lang.Double,java.lang.Integer,java.lang.Integer)
2019-08-23 09:08:44.198 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/degrade/delete.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.DegradeController.delete(javax.servlet.http.HttpServletRequest,java.lang.Long)
2019-08-23 09:08:44.199 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/degrade/rules.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.DegradeController.queryMachineRules(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer)
2019-08-23 09:08:44.200 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/degrade/save.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.DegradeController.updateIfNotNull(javax.servlet.http.HttpServletRequest,java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.Double,java.lang.Integer,java.lang.Integer)
2019-08-23 09:08:44.209 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/system/delete.json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<?> com.alibaba.csp.sentinel.dashboard.controller.SystemController.delete(javax.servlet.http.HttpServletRequest,java.lang.Long)
2019-08-23 09:08:44.210 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/system/rules.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.SystemController.apiQueryMachineRules(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer)
2019-08-23 09:08:44.212 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/system/new.json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.SystemController.apiAdd(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer,java.lang.Double,java.lang.Double,java.lang.Long,java.lang.Long,java.lang.Double)
2019-08-23 09:08:44.214 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/system/save.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.SystemController.apiUpdateIfNotNull(javax.servlet.http.HttpServletRequest,java.lang.Long,java.lang.String,java.lang.Double,java.lang.Double,java.lang.Long,java.lang.Long,java.lang.Double)
2019-08-23 09:08:44.219 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-08-23 09:08:44.221 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-08-23 09:08:44.236 INFO 42064 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
2019-08-23 09:08:44.276 INFO 42064 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-08-23 09:08:44.277 INFO 42064 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-08-23 09:08:44.546 INFO 42064 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2019-08-23 09:08:44.590 INFO 42064 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-08-23 09:08:44.599 INFO 42064 --- [ main] c.a.c.s.dashboard.DashboardApplication : Started DashboardApplication in 7.26 seconds (JVM running for 9.45)
2019-08-23 09:08:45.767 ERROR 42064 --- [nio-8080-exec-2] o.a.catalina.core.AprLifecycleListener : An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]
2019-08-23 09:08:45.783 INFO 42064 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2019-08-23 09:08:45.783 INFO 42064 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2019-08-23 09:08:45.812 INFO 42064 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 28 ms

  默认端口号是8080,我们在浏览器输入localhost:8080即可打开监控面板,默认用户名密码都是sentinel:0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

  接下来我们让服务提供方lxytrans-provider这个应用(原三板斧参见0.9.0.RELEASE版本的spring cloud alibaba nacos实例)接入到哨兵,加上sentinel相关内容:

  1、pom引入sentinel依赖:

        <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

  2、application引入sentinel dashboard地址:

#哨兵
spring.cloud.sentinel.transport.dashboard=localhost:8080

  3、controller加上注解@SentinelResource标识资源:

    @Slf4j
@RestController
static class TestController { @GetMapping("/hello")
@SentinelResource("hello")
public String hello() {
return "hello";
} @GetMapping("/hey")
@SentinelResource("hey")
public String hey() throws InterruptedException {
Thread.sleep(2000);
return "hey";
}

  打完收工。启动应用后,再访问localhost:8080,发现微服务已经接入,但是sentinel dashboard页面已然啥都木有。我们需要先访问一次接口,才能在sentinel dashboard上看到。那就先跑一把/hello和/hey,再去sentinel bashboard刷新下实时监控,接口出来了:

0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

  我们点下“簇点链路”,在对应的资源右边点击流控进行流控规则设置,点击降级则是设置降级规则。先试下流控。上面可以看到hello有3级资源,点击我们在@SentinelResource中指定的“hello”右边对应的流控按钮:

0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

  这里我们配置流控规则是每秒并发请求数为3,超过了就直接拒绝。点击新增按钮后跳到流控规则页面:

0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

  流控规则页面的右上角也可以直接添加规则的。现在我们通过jmeter来跑一个,jmeter设置线程数为4(具体设置参见jmeter使用经历):

0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

  我们看到并发调用了4次hello接口,其中一次失败了,日志打印如下:

2019-08-22 13:02:14.651 |-ERROR [http-nio-8282-exec-10] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] [175] -| Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.reflect.UndeclaredThrowableException] with root cause
com.alibaba.csp.sentinel.slots.block.flow.FlowException: null

  接下来我们通过另一个/hey接口试下降级,在“簇点链路”点击“hey”资源右边的降级按钮设置降级规则:

0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

  这里我们配置/hey接口如果时延超过100毫秒(5个一批,两批均超时,进入降级),那么接下来的10秒内,我们将拒绝请求。10秒后允许继续请求,如果还是超时,那么继续拒绝10秒。循环往复,生生不息。点击“新增”按钮后跳往降级规则页面:

0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

  同样的,在这个页面右上角也可以直接新增降级规则。我们在jmeter中新增一个/hey接口,禁用原来的/hello,再将线程数改为5,循环次数改为4,跑一把:

0.9.0.RELEASE版本的spring cloud alibaba sentinel实例

  /hey接口的时延是2秒,仔细看下这20个接口的请求时间,分4批请求,每批间隔2秒。可以发现第一批5个是正常通过的,接下第2批前4个也是正常通过的,后面11个全被拒绝了。日志打印:

2019-08-22 13:12:03.245 |-ERROR [http-nio-8282-exec-2] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] [175] -| Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.reflect.UndeclaredThrowableException] with root cause
com.alibaba.csp.sentinel.slots.block.degrade.DegradeException: null

  打完收工。注意如果应用重启后,sentinel dashboard的限流、降级配置就没了,需要重新请求一次,刷出资源后再重新配置。更多信息参考https://github.com/alibaba/Sentinel/wiki/介绍。关于服务提供方的限流、降级定制处理,参见0.9.0.RELEASE版本的spring cloud alibaba sentinel限流、降级处理实例

上一篇:java06switch


下一篇:javaweb学习记录(1)