I'm using Hystrix async for the first time to make a set call to a third-party library for which I really don't care if data was posted successfully or not.
public class SetCacheDataCommand extends BaseHystrixCommand {
public SetCacheDataCommand(CacheClient cacheClient, String cacheKey, Entry cacheValue, int timeToLive) {
super(HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GROUP_NAME))
.andCommandKey(HystrixCommandKey.Factory.asKey(COMMAND_NAME))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
.withExecutionTimeoutInMilliseconds(DEFAULT_HYSTRIX_TIMEOUT_MILLISECONDS)));
this.cacheClient = cacheClient;
this.cacheKey = cacheKey;
this.cacheValue = cacheValue;
this.timeToLive = timeToLive;
}
@Override
protected Object run() throws Exception {
cacheClient.set(cacheKey, cacheValue, timeToLive);
return null;
}
Set is a void method. Here is the command call:
....Doing something here
new SetCacheDataCommand(cacheClient, cacheKey, cacheValue, 10000).queue();
....Doing something here
I was hoping the above code will take care of making this call async. But I read the below from Hystrix documentation.
Note: Timeouts will fire on HystrixCommand.queue(), even if the caller never calls get() on the resulting Future. Before Hystrix 1.4.0, only calls to get() triggered the timeout mechanism to take effect in such a case.
They have also mentioned:
Note that there is configuration for turning off timeouts per-command, if that is desired (see command.timeout.enabled).
Couple of questions:
- If I Keep timeout flag enabled, Does it mean behavior would be synchronous? Do you see any problem if I turn off the timeout flag?
- What happens if there are let's say 20 thread in the pool and all these threads are busy making a Set call which is async?