Springcloud (3) Request fuse, service downgrade hystrix-supplement

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.