Hystrix the status of the fuse: if the service is not a problem is "off" state, the threshold is the number of requests, such as the threshold is 100 per 10s <100 times the request will not be detected, if the number of requests >100 will be detected if the success ratio <50% Then turn on the switch into the "open" state, when the fuse time window end will enter the "half open" state, the request is detected at this time, if the success becomes "off" state, or revert to "open" status.
Controllable parameters: threshold, detection time, fuse time
Problem with request demotion:
The fallback method is executed when the request is degraded, so what if there is a network request in the fallback method and the network request fails?
It is possible to downgrade two times, add @hystrixcommand annotations to the fallback method, so that the last level of fallback must not have a network request.
How does the fallback method exception catch when the request is degraded?
You can add the Throwable type parameter to the fallback method.
Parameters that omit the specified exception can be configured in the @hystrixcommand annotation.
Dependency Isolation:
@HystrixCommand (Groupkey = "", Threadpoolkey = "")
Adding these two parameters to the annotation, the first one is for grouping, and each group calls the same thread pool.
The second parameter is fine-grained in each group (same group but different task).
Request Cache:
Hystrix cache is cached in the request domain, the personal feel a little chicken ...
Example:
Or use the simplest of the custom hystrixservicecommand, using the example you wrote earlier
This method needs to be overridden in the command
@Override
Protected String Getcachekey () {
return "Hello";
}
Controller layer:
@RequestMapping ("/hystrix")
Public String Hellohystrix () {
Initializes the context, and if you do not add this or an error, the cache is cached in the request domain.
Hystrixrequestcontext.initializecontext ();
Hystrixservicecommand command = new Hystrixservicecommand ("Hello", resttemplate);
String execute = command.execute ();
return execute;
}
Then start the various services, access this address, and constantly refresh the page, found that the cache is not used because the cache is in the request domain.
So to demonstrate the effect, the change code is as follows:
Note that there must be a new two command, and a command can execute only once. The code can see the request cache after this change.
@RequestMapping ("/hystrix")
Public String Hellohystrix () {
list<string> list = new ArrayList ();
Initializes the context, and if you do not add this or an error, the cache is cached in the request domain.
Hystrixrequestcontext.initializecontext ();
Hystrixservicecommand command = new Hystrixservicecommand ("Hello", resttemplate);
String execute = command.execute ();
Hystrixservicecommand Command1 = new Hystrixservicecommand ("Hello", resttemplate);
String execute1 = Command1.execute ();
List.add (execute);
List.add (EXECUTE1);
return list.tostring ();
}
Request a Merge
Springcloud (3) Request fuse, service downgrade hystrix-supplement