Dry Goods sharing microservices spring-cloud (4. Load balancing ribbon and fuse hystrix)

Source: Internet
Author: User

Ribbonis a based onhttpand theTcpthe client Load Balancer tool

Hystrix with service degradation, service fuse, thread and signal isolation, request caching, request consolidation, and service monitoring

to facilitate consumer load balancing, copy demo-springcloud-client1 and rename demo-springcloud-client2, modify configuration files and startup classes, service provider 1 and 2 service names are spring.application.name=demo-springcloud-client

Modify Yhqcontoller implementation, in order to facilitate load balancing observation effect,Demo-springcloud-client2 project return string Client2

Create a consumer project Demo-springcloud-resttemplate-consumer, create a startup class Resttemplateapplication, @EnableDiscoveryClient Start service discovery and enroll for automatic configuration To be able to discover the previously registered service providers Demo-springcloud-client1 and Demo-springcloud-client2. @EnableCircuitBreaker turn on fuse auto-configuration

Create a load-balanced resttemplate, @Bean and use the @loadbalanced qualifier. If there is no spring-cloud-starter-ribbon dependency, the @LoadBalanced load-balancing polling algorithm will not take effect. Using Spring-cloud-starter-eureka dependency, the Ribbon service discovery will be delivered to Eureka. Add fuse dependent Spring-cloud-starter-hystrix

Create Yhqcontroller provide rest service Resttemplateconsumer to consume prior services 1 and 2,

The service calls our service provider Demo-springcloud-client1 and Demo-springcloud-client2 by injecting the Yhqservice resttemplate object Load Balancer

Start the registry, start service Providers 1 and 2, start consumer Demo-springcloud-resttemplate-consumer, browser access http://localhost:3331/ Resttemplateconsumer returns the string client1 and Client2 alternating, which is the result of load balancing polling.

Fuse Hystrix uses the fallback method used when the fallback command fails to implement the degraded processing logic for the service. This closes the service provider Demo-springcloud-client2, and the browser accesses Http://localhost:3331/restTemplateConsumer returns The string client1 and I was demoted logical alternate appear

When implementing a fuse through the annotation method, set the property value by using @hystrixcommand's commandproperties, such as setting fallback.enabled

Dry Goods sharing microservices spring-cloud (4. Load balancing ribbon and fuse hystrix)

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.