Coder Social home page Coder Social logo

Comments (17)

blackr1234 avatar blackr1234 commented on June 18, 2024 4

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 of or for each method, you cannot set it on a class by class basis.

Thank you.

from spring-cloud-openfeign.

ryanjbaxter avatar ryanjbaxter commented on June 18, 2024 2

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.

userheng avatar userheng commented on June 18, 2024 2

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.

thorstenfrank avatar thorstenfrank commented on June 18, 2024

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.

dsyer avatar dsyer commented on June 18, 2024

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.

spencergibb avatar spencergibb commented on June 18, 2024

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.

robojeff avatar robojeff commented on June 18, 2024

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.

robojeff avatar robojeff commented on June 18, 2024

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.

ryanjbaxter avatar ryanjbaxter commented on June 18, 2024

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.

robojeff avatar robojeff commented on June 18, 2024

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.

ryanjbaxter avatar ryanjbaxter commented on June 18, 2024

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.

thorstenfrank avatar thorstenfrank commented on June 18, 2024

If you really want all methods of the two @FeignClients 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.

jingyimou avatar jingyimou commented on June 18, 2024

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.

ryanjbaxter avatar ryanjbaxter commented on June 18, 2024

@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.

Felfan avatar Felfan commented on June 18, 2024

`

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.

unxia avatar unxia commented on June 18, 2024

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.

OlgaMaciaszek avatar OlgaMaciaszek commented on June 18, 2024

Closing issue as Hystrix no longer supported.

from spring-cloud-openfeign.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.