Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javanica: Dynamic thread pool key, based on parameters #350

Closed
jochenchrist opened this issue Dec 5, 2014 · 3 comments
Closed

Javanica: Dynamic thread pool key, based on parameters #350

jochenchrist opened this issue Dec 5, 2014 · 3 comments

Comments

@jochenchrist
Copy link

With hystrix-javanica, is there a way to define the hystrix thread pool dynamically, based on the Hystrix Command parameters?

To clarify:
In the example below, I'd like to use a different thread pool for each different bank value.

Example:

    @HystrixCommand(fallbackMethod = "getBalanceFromCache")
    public AccountBalance getBalance(Bank bank, String iban) {
        final String bankUrl = environment.getProperty("bank." + bank.name().toLowerCase());
        final URI uri = UriComponentsBuilder.fromHttpUrl(bankUrl).buildAndExpand(iban).toUri();
        return restTemplate.getForObject(uri, AccountBalance.class);
    }

    public AccountBalance getBalanceFromCache(Bank bank, String iban) {
        logger.info("GET Fallback for Bank {}", bank);
        return AccountBalanceCache.getCachedAccountBalance(bank, iban);
    }

A possible approach would be to define a threadPoolKeyMethod with the same parameters as the hystrix command, similar to the fallbackMethod, which provides a key to use.

    @HystrixCommand(fallbackMethod = "getBalanceFromCache", threadPoolKeyMethod = "threadPoolKey")
    public AccountBalance getBalance(Bank bank, String iban) {
        final String bankUrl = environment.getProperty("bank." + bank.name().toLowerCase());
        final URI uri = UriComponentsBuilder.fromHttpUrl(bankUrl).buildAndExpand(iban).toUri();
        return restTemplate.getForObject(uri, AccountBalance.class);
    }

    public HystrixThreadPoolKey threadPoolKey(Bank bank, String iban) {
        return HystrixThreadPoolKey.Factory.asKey("getBalance_" + bank);
    }

Ideas?

@dmgcodevil
Copy link
Contributor

No, there is no such ability. If I got you correctly you need to generate thread pools in runtime with keys based on command parameters, but I my opinion it can lead to many thread pool instances, did you think about that ? Curious, why you need that ability, as variant you can create different methods, annotate them using @HystrixCommand annotation and invoke certain method based on parameters of root method. For example:

public AccountBalance getBalance(Bank bank, String iban) {
          if (bank.getName() == "Great Trust Bank") {
                return getGTBankBalance(bank, iban);
           }
    }

@HystrixCommand(threadPoolKey = "YourSpecificThreadPoolKey")
public AccountBalance getGTBankBalance(Bank bank, String iban) {
           ....
    }

But I'm not sure that this will work within same class i.e. if 'getBalance' and 'getGTBankBalance' defined in the same class
Could you check will this approach work for you ? If not then I'll implement this feature.

@benjchristensen benjchristensen changed the title Dynamic thread pool key, based on parameters Javanica: Dynamic thread pool key, based on parameters Dec 12, 2014
@mattrjacobs
Copy link
Contributor

Closing due to inactivity. If there is still interest in this, please reopen

@anjia0532
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants