Add commandProperties in HystrixCommands (#2656)
This commit is contained in:
committed by
Spencer Gibb
parent
06672462ab
commit
89cb8d1d9c
@@ -23,6 +23,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import com.netflix.hystrix.HystrixCommandKey;
|
||||
import com.netflix.hystrix.HystrixCommandProperties;
|
||||
import com.netflix.hystrix.HystrixObservableCommand;
|
||||
import com.netflix.hystrix.HystrixObservableCommand.Setter;
|
||||
|
||||
@@ -49,6 +50,7 @@ public class HystrixCommands {
|
||||
private String groupName;
|
||||
private Publisher<T> fallback;
|
||||
private Setter setter;
|
||||
private HystrixCommandProperties.Setter commandProperties;
|
||||
private boolean eager = false;
|
||||
private Function<HystrixObservableCommand<T>, Observable<T>> toObservable;
|
||||
|
||||
@@ -76,6 +78,22 @@ public class HystrixCommands {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublisherBuilder<T> commandProperties(
|
||||
HystrixCommandProperties.Setter commandProperties) {
|
||||
this.commandProperties = commandProperties;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublisherBuilder<T> commandProperties(
|
||||
Function<HystrixCommandProperties.Setter, HystrixCommandProperties.Setter> commandProperties) {
|
||||
if (commandProperties == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"commandProperties must not both be null");
|
||||
}
|
||||
return this.commandProperties(
|
||||
commandProperties.apply(HystrixCommandProperties.Setter()));
|
||||
}
|
||||
|
||||
public PublisherBuilder<T> eager() {
|
||||
this.eager = true;
|
||||
return this;
|
||||
@@ -126,7 +144,11 @@ public class HystrixCommands {
|
||||
|
||||
HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey(groupNameToUse);
|
||||
HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey(this.commandName);
|
||||
setterToUse = Setter.withGroupKey(groupKey).andCommandKey(commandKey);
|
||||
HystrixCommandProperties.Setter commandProperties = this.commandProperties != null
|
||||
? this.commandProperties
|
||||
: HystrixCommandProperties.Setter();
|
||||
setterToUse = Setter.withGroupKey(groupKey).andCommandKey(commandKey)
|
||||
.andCommandPropertiesDefaults(commandProperties);
|
||||
}
|
||||
return setterToUse;
|
||||
}
|
||||
|
||||
@@ -134,4 +134,17 @@ public class HystrixCommandsTests {
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extendTimeout() {
|
||||
StepVerifier.create(HystrixCommands.from(Mono.fromCallable(() -> {
|
||||
Thread.sleep(1500);
|
||||
return "works";
|
||||
})).commandName("extendTimeout")
|
||||
.commandProperties(
|
||||
setter -> setter.withExecutionTimeoutInMilliseconds(2000))
|
||||
.toMono())
|
||||
.expectNext("works")
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user