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> ...@@ -55,7 +55,7 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
private Verb verb; private Verb verb;
private URI uri; private URI uri;
private Boolean retryable; private Boolean retryable;
private MultiValueMap<String, String> headers; private MultiValueMap<String, String> headers;
...@@ -97,7 +97,7 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse> ...@@ -97,7 +97,7 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
.withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE) .withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE)
.withExecutionIsolationSemaphoreMaxConcurrentRequests(value.get()); .withExecutionIsolationSemaphoreMaxConcurrentRequests(value.get());
return Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RibbonCommand")) return Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RibbonCommand"))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey + "RibbonCommand")) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey))
.andCommandPropertiesDefaults(setter); .andCommandPropertiesDefaults(setter);
} }
...@@ -110,11 +110,11 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse> ...@@ -110,11 +110,11 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
RequestContext context = RequestContext.getCurrentContext(); RequestContext context = RequestContext.getCurrentContext();
Builder builder = HttpRequest.newBuilder().verb(this.verb).uri(this.uri) Builder builder = HttpRequest.newBuilder().verb(this.verb).uri(this.uri)
.entity(this.requestEntity); .entity(this.requestEntity);
if(retryable != null) { if(this.retryable != null) {
builder.setRetriable(retryable); builder.setRetriable(this.retryable);
} }
for (String name : this.headers.keySet()) { for (String name : this.headers.keySet()) {
List<String> values = this.headers.get(name); List<String> values = this.headers.get(name);
for (String value : values) { for (String value : values) {
...@@ -134,11 +134,11 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse> ...@@ -134,11 +134,11 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
HttpResponse response = this.restClient HttpResponse response = this.restClient
.executeWithLoadBalancer(httpClientRequest); .executeWithLoadBalancer(httpClientRequest);
context.set("ribbonResponse", response); context.set("ribbonResponse", response);
// Explicitly close the HttpResponse if the Hystrix command timed out to // Explicitly close the HttpResponse if the Hystrix command timed out to
// release the underlying HTTP connection held by the response. // release the underlying HTTP connection held by the response.
// //
if( this.isResponseTimedOut() ) { if( this.isResponseTimedOut() ) {
if( response!= null ) { if( response!= null ) {
response.close(); response.close();
} }
...@@ -154,30 +154,30 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse> ...@@ -154,30 +154,30 @@ public class RestClientRibbonCommand extends HystrixCommand<ClientHttpResponse>
} }
protected MultiValueMap<String, String> getHeaders() { protected MultiValueMap<String, String> getHeaders() {
return headers; return this.headers;
} }
protected MultiValueMap<String, String> getParams() { protected MultiValueMap<String, String> getParams() {
return params; return this.params;
} }
protected InputStream getRequestEntity() { protected InputStream getRequestEntity() {
return requestEntity; return this.requestEntity;
} }
protected RestClient getRestClient() { protected RestClient getRestClient() {
return restClient; return this.restClient;
} }
protected Boolean getRetryable() { protected Boolean getRetryable() {
return retryable; return this.retryable;
} }
protected URI getUri() { protected URI getUri() {
return uri; return this.uri;
} }
protected Verb getVerb() { protected Verb getVerb() {
return verb; return this.verb;
} }
} }
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
package org.springframework.cloud.netflix.zuul.filters.route; package org.springframework.cloud.netflix.zuul.filters.route;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import com.netflix.client.http.HttpRequest; import com.netflix.client.http.HttpRequest;
import com.netflix.niws.client.http.RestClient; import com.netflix.niws.client.http.RestClient;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
...@@ -45,7 +47,7 @@ public class RestClientRibbonCommandFactory implements RibbonCommandFactory<Rest ...@@ -45,7 +47,7 @@ public class RestClientRibbonCommandFactory implements RibbonCommandFactory<Rest
} }
protected SpringClientFactory getClientFactory() { protected SpringClientFactory getClientFactory() {
return clientFactory; return this.clientFactory;
} }
protected static HttpRequest.Verb getVerb(String sMethod) { 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