Commit f1f239d7 by Dave Syer

Change hystrix command key to be the service ID in Zuul proxy

When using Ribbon the hystrix config and metrics are namespaced as "RibbonCommand" (via the group key). the command key can then be serviceId, making it easier to remember how to configure Ribbon and Hystrix. Fixes gh-329
parent 0141a13c
......@@ -55,7 +55,7 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
private Verb verb;
private URI uri;
private Boolean retryable;
private MultiValueMap<String, String> headers;
......@@ -97,7 +97,7 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
.withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE)
.withExecutionIsolationSemaphoreMaxConcurrentRequests(value.get());
return Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RibbonCommand"))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey + "RibbonCommand"))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey))
.andCommandPropertiesDefaults(setter);
}
......@@ -110,11 +110,11 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
RequestContext context = RequestContext.getCurrentContext();
Builder builder = HttpRequest.newBuilder().verb(this.verb).uri(this.uri)
.entity(this.requestEntity);
if(retryable != null) {
builder.setRetriable(retryable);
if(this.retryable != null) {
builder.setRetriable(this.retryable);
}
for (String name : this.headers.keySet()) {
List<String> values = this.headers.get(name);
for (String value : values) {
......@@ -134,11 +134,11 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
HttpResponse response = this.restClient
.executeWithLoadBalancer(httpClientRequest);
context.set("ribbonResponse", response);
// Explicitly close the HttpResponse if the Hystrix command timed out to
// release the underlying HTTP connection held by the response.
//
if( this.isResponseTimedOut() ) {
//
if( this.isResponseTimedOut() ) {
if( response!= null ) {
response.close();
}
......@@ -154,30 +154,30 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
}
protected MultiValueMap<String, String> getHeaders() {
return headers;
return this.headers;
}
protected MultiValueMap<String, String> getParams() {
return params;
return this.params;
}
protected InputStream getRequestEntity() {
return requestEntity;
return this.requestEntity;
}
protected RestClient getRestClient() {
return restClient;
return this.restClient;
}
protected Boolean getRetryable() {
return retryable;
return this.retryable;
}
protected URI getUri() {
return uri;
return this.uri;
}
protected Verb getVerb() {
return verb;
return this.verb;
}
}
......@@ -16,10 +16,12 @@
package org.springframework.cloud.netflix.zuul.filters.route;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import com.netflix.client.http.HttpRequest;
import com.netflix.niws.client.http.RestClient;
import lombok.SneakyThrows;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
/**
* @author Spencer Gibb
......@@ -45,7 +47,7 @@ public class RestClientRibbonCommandFactory implements RibbonCommandFactory<Rest
}
protected SpringClientFactory getClientFactory() {
return clientFactory;
return this.clientFactory;
}
protected static HttpRequest.Verb getVerb(String sMethod) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment