Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Providing Hystrix Fallbacks for Routes in Zuul

DZone's Guide to

Providing Hystrix Fallbacks for Routes in Zuul

Read on for somes insight into utilizing fallbacks for Zuul routes in a Netflix OSS implementation of Spring Cloud.

· Cloud Zone
Free Resource

Download the Essential Cloud Buyer’s Guide to learn important factors to consider before selecting a provider as well as buying criteria to help you make the best decision for your infrastructure needs, brought to you in partnership with Internap.

If you are a user of Zuul from Spring Cloud Netflix, then you likely know that all the routes you configure that use Ribbon are also wrapped in Hystrix commands. This nice little feature provides a circuit breaker for all your proxied requests through Zuul. When the circuit is tripped it can save the proxied service from becoming too overloaded and perhaps also save your app from appearing to be “slow”.

If you have ever looked at Hystrix before, you know that you can generally provide a fallback for the circuit. The fallback provides some default functionality for the circuit when the circuit is tripped. For example, if you wrap a request to a service in a Hystrix Command and provide a fallback, than when the circuit is tripped and a request is made to the service the fallback will be invoked instead. What would the fallback return? One logical response would be to return back a cached response. This combination of circuit breaker + fallback allows for the downstream service to recover while still providing a somewhat meaningful response back to the calling service.

Up until now, it was not possible to provide a fallback when a circuit was tripped for a given route in Zuul. The latest Camden snapshot builds now include a feature allowing you to specify fallbacks for your routes configured in Zuul. (All releases prior to, and including Camden.SR1 do NOT include this functionality.) It is very simple to provide a fallback for a route in Zuul. All you have to do is provide a bean that implements ZuulFallbackProvider in your app. Within that bean, you specify the route ID you want the fallback to apply to and provide a ClientHttpResponse object to return when the fallback is invoked. For more information see the Spring Cloud docs. If you would like to see a working example check out the Zuul Server sample on GitHub.

The Cloud Zone is brought to you in partnership with Internap. Read Bare-Metal Cloud 101 to learn about bare-metal cloud and how it has emerged as a way to complement virtualized services.

Topics:
spring cloud ,netflix oss ,zuul ,hystrix ,cloud

Published at DZone with permission of Ryan Baxter, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}