Comments (17)
No you either set it for all Feign clients of for each method, you can set it on a class by class basis. There is no need to create a
SetterFactory
when using the properties.
Thanks for your contribution, but would you correct the typo please:
No , you either set it for all Feign clients
ofor for each method, you cannot set it on a class by class basis.
Thank you.
from spring-cloud-openfeign.
If you had a Feign client called MyClient
and it had a method called search
that took in a single String
parameter than you would use the following property
hystrix.command.MyClient#search(String).execution.isolation.thread.timeoutInMilliseconds
from spring-cloud-openfeign.
i think configure better in this way:
`
@configuration
@ConditionalOnClass({ HystrixCommand.class, HystrixFeign.class })
public class CustomeHystrixFeignConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "feign.hystrix.enabled")
public Feign.Builder feignHystrixBuilder() {
SetterFactory setterFactory = new SetterFactory() {
@Override
public Setter create(Target<?> target, Method method) {
String groupKey = target.name();
String commandKey = /* Feign.configKey(target.type(), method); */target.name();
return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
}
};
return HystrixFeign.builder().setterFactory(setterFactory);
}
}
`
from spring-cloud-openfeign.
You mention having different feign clients - are the @Configuration
beans you're using included in the component scan of your application?
from spring-cloud-openfeign.
It looks like you have figured out the magic formula. We should document it better though, for sure.
The way to customize the command keys is indeed to provide a SetterFactory
bean in the feign spring configuration (that's a Feign abstraction). We could document that more too. I'm not sure if your strategy is a good one, in the case that there are multiple methods per client interface.
from spring-cloud-openfeign.
Yup, that is why the key was chosen as the signature because that is the only way to isolate the method.
from spring-cloud-openfeign.
I have 2 @FeignClient interfaces, each with many methods. How can I set the hystrix timeout (hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds) for each client (the same timeout value for each method in the interface)? I'm confused as to how to use the SetterFactory in my FeignConfig bean. Thanks!
from spring-cloud-openfeign.
My feign clients have many methods. Are you saying I need to specify a property in my config file for each method, and then declare the SetterFactory in my Feign configuration bean? That's a lot of work. There's no way to specify a timeout for ALL methods of a @FeignClient interface?
from spring-cloud-openfeign.
No you either set it for all Feign clients of for each method, you can set it on a class by class basis. There is no need to create a SetterFactory
when using the properties.
from spring-cloud-openfeign.
Ryan, thanks for the replies. But here's the problem: I've defined 2 @FeignClient interfaces (this is a spring boot app). In my application.yml file, I've attempted to define separate timeout configs for each, but Hystrix is using the default timeout of 1 second. I've defined client-specific ribbon configurations and hystrix configurations as follows:
my-service-1:
ribbon:
ReadTimeout: 5250
MaxAutoRetries: 2
OkToRetryOnAllOperations: false
listOfServers: http://localhost:8200
my-service-2:
ribbon:
ReadTimeout: 5250
MaxAutoRetries: 2
OkToRetryOnAllOperations: false
listOfServers: http://localhost:8201
hystrix:
command:
my-service-1:
execution:
isolation:
thread:
timeoutInMilliseconds: 10750
my-service-2:
execution:
isolation:
thread:
timeoutInMilliseconds: 10750
My clients are defined like so:
@FeignClient(
value = "my-service-1",
configuration = ServiceAccountFeignClientConfig.class,
fallbackFactory = MyService1FallbackFactory.class
)
public interface MyServiceClient1 {...}
@FeignClient(
value = "my-service-2",
configuration = ServiceAccountFeignClientConfig.class,
fallbackFactory = MyService2FallbackFactory.class
)
public interface MyServiceClient2 {...}
The desired timeout is 10750 for both my-service-1 and my-service-2 and use the default Hystrix timeout for all other clients in the app.
Where have I gone wrong?
from spring-cloud-openfeign.
my-service-1
and my-service-2
are not valid Hystrix command ids. When Hystrix is used with Feign we wrap each method in the Feign client in its own Hystrix command so each method can have its own timeout. That is why you can only set the Hystrix timeouts for each method in the Feign Client and not for the entire Feign Client.
from spring-cloud-openfeign.
If you really want all methods of the two @FeignClient
s to share the same timeout (and/or thread pool), you need to use a SetterFactory
in your configuration and assign the same Hystrix command and/or group keys.
from spring-cloud-openfeign.
If a method has more than one parameter, how could I use the property of hystrix.command.MyClient#search(String).execution.isolation.thread.timeoutInMilliseconds?
I has tried MyClient#search(String,String,String,...),but it didn't work.
from spring-cloud-openfeign.
@jingyimou that is the correct command key pattern but you also need to configure ribbon timeouts if you are using that as well. If it is still not working please open a separate issue.
from spring-cloud-openfeign.
`
FeignClient:
@FeignClient(value = "service-res", fallbackFactory = ResVenClientFallBack.class)
@RequestMapping(value = "/res/ven")
public interface ResVenClient {
@RequestMapping(value = "/getTree", method = RequestMethod.GET)
ResultBean<ResVO> getTree();
}
yml:
hystrix:
command:
default:
execution:
isolation:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 30000
interruptOnTimeout: true
interruptOnFutureCancel: false
ResVenClient#getTree():
fallback:
enabled: true
execution:
timeout:
enabled: true
isolation:
thread:
timeoutInMilliseconds: 45000
feign:
hystrix:
enabled: true
client:
config:
default:
connectTimeout: 15000
readTimeout: 15000`
1.When feign.client.config.default is not configured,about 2s out of time;???
2.When feign.client.config.default is configured,about 15s not 30 out of time;???
can you give me help? thank you very much .-_-
from spring-cloud-openfeign.
Hystrix use CircuitBreakerNameResolver to naming circuit as command key, there is a default implementation DefaultCircuitBreakerNameResolver, which output key pattern is HardCodedTarget#methodName(ParamClass), or customize CircuitBreakerNameResolver instead of DefaultCircuitBreakerNameResolver.
from spring-cloud-openfeign.
Closing issue as Hystrix no longer supported.
from spring-cloud-openfeign.
Related Issues (20)
- Default request header headers overwriten with specific client configuration and shared by all clients HOT 1
- PlaytikaOSS feign-reactive does not support spring boot 3.2.x HOT 1
- @PatchMapping and @DeleteMapping insert unwanted slash when using url and specific value HOT 3
- FeignClientFactoryBean dismiss404 default config overrides client-specific config HOT 1
- Multiple implementations of ResponseInterceptor fail to trigger HOT 10
- Want to understand , is Spring Openfeign is in Deprecated path HOT 2
- Maintain the span from HTTP calls using feign clients with micrometer HOT 1
- Micrometer tracing propagation not working when using Spring FactoryBean and Feign HOT 1
- Custom HTTP codes are not supported HOT 1
- B3 span and parentId headers not propagated with spring-cloud-openfeign and brave HOT 1
- Remove unused spring-boot-starter-aop dependency HOT 1
- [sentinel] openfeign+sentinel Error HOT 2
- Spring Boot 3.2.4 (Cloud 2023.0.1) Cannot deserialize "pageable": "INSTANCE" HOT 5
- Issue with registering method parameter hints HOT 3
- `FeignClientsRegistar` fails when trying to parse unresolved property placeholders in JDK 20+ HOT 1
- "text/plain" Not working when dealing with the ISO_8859_1 HOT 1
- feign.codec.EncodeException: null HOT 3
- RequestInterceptor not injecting headers after upgrading it to 2023.0.1
- Default http client (Client.Default) seems not taking 'spring.cloud.openfeign.httpclient' properties when creating feign client with FeignClientBuilder HOT 1
- FeignClients auto config
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-cloud-openfeign.