Ribbon retry works & fix Content-Length error.
This change requires setting `ribbon.http.client.enabled=true`. This change addresses issue #648 Getting Retry Working In RestTemplate. There is also a fix in place that addresses the issue #357 RestTemplate Error. fixes gh-648
This commit is contained in:
committed by
Spencer Gibb
parent
a3ab3259e3
commit
05351b7809
@@ -16,13 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.netflix.ribbon.eureka;
|
||||
|
||||
import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses;
|
||||
import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
@@ -35,14 +30,18 @@ import com.netflix.appinfo.EurekaInstanceConfig;
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import com.netflix.config.ConfigurationManager;
|
||||
import com.netflix.config.DeploymentContext.ContextKey;
|
||||
import com.netflix.config.DynamicPropertyFactory;
|
||||
import com.netflix.config.DynamicStringProperty;
|
||||
import com.netflix.discovery.EurekaClientConfig;
|
||||
import com.netflix.loadbalancer.IPing;
|
||||
import com.netflix.loadbalancer.ServerList;
|
||||
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
|
||||
import com.netflix.niws.loadbalancer.NIWSDiscoveryPing;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
|
||||
import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses;
|
||||
import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity;
|
||||
import static org.springframework.cloud.netflix.ribbon.RibbonProperyUtils.setRibbonProperty;
|
||||
|
||||
/**
|
||||
* Preprocessor that configures defaults for eureka-discovered ribbon clients. Such as:
|
||||
* <code>@zone</code>, NIWSServerListClassName, DeploymentContextBasedVipAddresses,
|
||||
@@ -62,10 +61,6 @@ public class EurekaRibbonClientConfiguration {
|
||||
@Value("${ribbon.client.name}")
|
||||
private String serviceId = "client";
|
||||
|
||||
protected static final String VALUE_NOT_SET = "__not__set__";
|
||||
|
||||
protected static final String DEFAULT_NAMESPACE = "ribbon";
|
||||
|
||||
@Autowired(required = false)
|
||||
private EurekaClientConfig clientConfig;
|
||||
|
||||
@@ -132,25 +127,8 @@ public class EurekaRibbonClientConfiguration {
|
||||
}
|
||||
}
|
||||
}
|
||||
setProp(this.serviceId, DeploymentContextBasedVipAddresses.key(), this.serviceId);
|
||||
setProp(this.serviceId, EnableZoneAffinity.key(), "true");
|
||||
}
|
||||
|
||||
protected void setProp(String serviceId, String suffix, String value) {
|
||||
// how to set the namespace properly?
|
||||
String key = getKey(serviceId, suffix);
|
||||
DynamicStringProperty property = getProperty(key);
|
||||
if (property.get().equals(VALUE_NOT_SET)) {
|
||||
ConfigurationManager.getConfigInstance().setProperty(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected DynamicStringProperty getProperty(String key) {
|
||||
return DynamicPropertyFactory.getInstance().getStringProperty(key, VALUE_NOT_SET);
|
||||
}
|
||||
|
||||
protected String getKey(String serviceId, String suffix) {
|
||||
return serviceId + "." + DEFAULT_NAMESPACE + "." + suffix;
|
||||
setRibbonProperty(this.serviceId, DeploymentContextBasedVipAddresses.key(), this.serviceId);
|
||||
setRibbonProperty(this.serviceId, EnableZoneAffinity.key(), "true");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientConfiguration.VALUE_NOT_SET;
|
||||
|
||||
import static org.springframework.cloud.netflix.ribbon.RibbonProperyUtils.*;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -82,12 +83,12 @@ public class EurekaRibbonClientConfigurationTests {
|
||||
String serviceId = "myService";
|
||||
String suffix = "mySuffix";
|
||||
String value = "myValue";
|
||||
DynamicStringProperty property = preprocessor.getProperty(preprocessor.getKey(
|
||||
DynamicStringProperty property = getProperty(getRibbonKey(
|
||||
serviceId, suffix));
|
||||
assertEquals("property doesn't have default value", VALUE_NOT_SET, property.get());
|
||||
preprocessor.setProp(serviceId, suffix, value);
|
||||
setRibbonProperty(serviceId, suffix, value);
|
||||
assertEquals("property has wrong value", value, property.get());
|
||||
preprocessor.setProp(serviceId, suffix, value);
|
||||
setRibbonProperty(serviceId, suffix, value);
|
||||
assertEquals("property has wrong value", value, property.get());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user