Browse Source

Add commandProperties in HystrixCommands (#2656)

pull/6/head
Toshiaki Maki 7 years ago committed by Spencer Gibb
parent
commit
89cb8d1d9c
  1. 24
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixCommands.java
  2. 13
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCommandsTests.java

24
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixCommands.java

@ -23,6 +23,7 @@ import org.springframework.util.StringUtils; @@ -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 { @@ -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 { @@ -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 { @@ -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;
}

13
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCommandsTests.java

@ -134,4 +134,17 @@ public class HystrixCommandsTests { @@ -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();
}
}

Loading…
Cancel
Save