Commit 54c052c5 by Ryan Baxter

Disable Hystrix support when using Feign by default. Fixes #1277.

parent de886d6c
......@@ -1062,9 +1062,7 @@ NOTE: `PROD-SVC` is the name of the service the Clients will be making requests
[[spring-cloud-feign-hystrix]]
=== Feign Hystrix Support
If Hystrix is on the classpath, by default Feign will wrap all methods with a circuit breaker. Returning a `com.netflix.hystrix.HystrixCommand` is also available. This lets you use reactive patterns (with a call to `.toObservable()` or `.observe()` or asynchronous use (with a call to `.queue()`).
To disable Hystrix support for Feign, set `feign.hystrix.enabled=false`.
If Hystrix is on the classpath and `feign.hystrix.enabled=true`, Feign will wrap all methods with a circuit breaker. Returning a `com.netflix.hystrix.HystrixCommand` is also available. This lets you use reactive patterns (with a call to `.toObservable()` or `.observe()` or asynchronous use (with a call to `.queue()`).
To disable Hystrix support on a per-client basis create a vanilla `Feign.Builder` with the "prototype" scope, e.g.:
......
......@@ -98,7 +98,7 @@ public class FeignClientsConfiguration {
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "feign.hystrix.enabled", matchIfMissing = true)
@ConditionalOnProperty(name = "feign.hystrix.enabled", matchIfMissing = false)
public Feign.Builder feignHystrixBuilder() {
return HystrixFeign.builder();
}
......
......@@ -74,7 +74,7 @@ public class HystrixSecurityAutoConfiguration {
super(ConfigurationPhase.REGISTER_BEAN);
}
@ConditionalOnProperty(name = "feign.hystrix.enabled", matchIfMissing = true)
@ConditionalOnProperty(name = "feign.hystrix.enabled", matchIfMissing = false)
static class HystrixEnabled {
}
......
......@@ -35,7 +35,6 @@ import feign.Feign;
import feign.Logger;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.hystrix.HystrixFeign;
import feign.slf4j.Slf4jLogger;
/**
......@@ -73,7 +72,7 @@ public class EnableFeignClientsTests {
@Test
public void builderDefaultCorrect() {
HystrixFeign.Builder.class
Feign.Builder.class
.cast(this.feignContext.getInstance("foo", Feign.Builder.class));
}
......
......@@ -121,8 +121,8 @@ public class FeignClientOverrideDefaultsTests {
@Test
public void overrideBuilder() {
Feign.Builder.class.cast(this.context.getInstance("foo", Feign.Builder.class));
HystrixFeign.Builder.class
HystrixFeign.Builder.class.cast(this.context.getInstance("foo", Feign.Builder.class));
Feign.Builder.class
.cast(this.context.getInstance("bar", Feign.Builder.class));
}
......@@ -187,7 +187,7 @@ public class FeignClientOverrideDefaultsTests {
@Bean
public Feign.Builder feignBuilder() {
return Feign.builder();
return HystrixFeign.builder();
}
}
......
......@@ -16,7 +16,10 @@
package org.springframework.cloud.netflix.feign.invalid;
import feign.Feign;
import feign.hystrix.FallbackFactory;
import feign.hystrix.HystrixFeign;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -128,6 +131,10 @@ public class FeignClientValidationTests {
}
}
@Bean
public Feign.Builder feignBuilder() {
return HystrixFeign.builder();
}
}
@Test
......@@ -158,6 +165,11 @@ public class FeignClientValidationTests {
class Dummy {
}
@Bean
public Feign.Builder feignBuilder() {
return HystrixFeign.builder();
}
}
@Test
......@@ -187,6 +199,11 @@ public class FeignClientValidationTests {
return null;
}
}
@Bean
public Feign.Builder feignBuilder() {
return HystrixFeign.builder();
}
}
@Test
......@@ -217,6 +234,11 @@ public class FeignClientValidationTests {
class Dummy {
}
@Bean
public Feign.Builder feignBuilder() {
return HystrixFeign.builder();
}
}
@Test
......@@ -252,5 +274,10 @@ public class FeignClientValidationTests {
}
}
@Bean
public Feign.Builder feignBuilder() {
return HystrixFeign.builder();
}
}
}
......@@ -97,7 +97,8 @@ import rx.Single;
@SpringBootTest(classes = FeignClientTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
"spring.application.name=feignclienttest",
"logging.level.org.springframework.cloud.netflix.feign.valid=DEBUG",
"feign.httpclient.enabled=false", "feign.okhttp.enabled=false" })
"feign.httpclient.enabled=false", "feign.okhttp.enabled=false",
"feign.hystrix.enabled=true"})
@DirtiesContext
public class FeignClientTests {
......
......@@ -40,7 +40,7 @@ import org.springframework.web.client.RestTemplate;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
@SpringBootTest(classes = HystrixSecurityApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = "username.ribbon.listOfServers=localhost:${local.server.port}")
@SpringBootTest(classes = HystrixSecurityApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"username.ribbon.listOfServers=localhost:${local.server.port}","feign.hystrix.enabled=true"})
public class HystrixSecurityTests {
@Autowired
private CustomConcurrenyStrategy customConcurrenyStrategy;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment