Spring cloud - how to get benefits of retry,load balancing and circuit breaker for distributed spring application

杀马特。学长 韩版系。学妹 提交于 2019-12-01 05:42:56

I do see there is a @FeignClient. Does it help with retry and circuit breaker and load balancing all-in-one?

If you are using the full spring-cloud stack, it actually solves everything you mentioned.

The netflix components in this scenario are the following in spring-cloud:

Eureka - Service Registry

Let's you dyanmically register your services so you only need to fix one host in your app (eureka).

Ribbon - Load balancer

Out of the box it's providing you with round robin loadbalancing, but you can implement your own @RibbonClient (even for a specific service) and design your custom loadbalancing for example based on eureka metadata. The loadbalancing happens on the client side.

Feign - Http client

With @FeignClient you can rapidly develop clients for you other services (or services outside of your infrastructure). It is integrated with ribbon and eureka so you can refer to your services @FeignClient(yourServiceNameInEureka) and what you end up with is a client which loadbalances between the registered instances with your preferred logic. If you are using spring you can use the familiar @RequestMapping annotation to describe the endpoint you are using.

Hystrix - Circuit breaker

By default your feign clients will use hystrix, every request will be wrapped in a hystrix command. You can of course create hytrix commands by hand and configure them for your needs.

You have to configure a little to get thees working (actually just a few @Enable annotation on your configuration).

I highly recommend reading the provided spring documentation because it wraps up almost all of your aspects in a fairly quick read.

http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!