Skip to content

Commit

Permalink
EUREKA-1087 Add config parameter eureka.myUrl to specify URL Eureka s…
Browse files Browse the repository at this point in the history
…hould treat as its own (for cases when each Eureka node is behind LB and does not simply check replica URLs against own IP/host)
  • Loading branch information
Mikhail Gromov committed Aug 2, 2018
1 parent e68bde7 commit 01de9e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class DefaultEurekaServerConfig implements EurekaServerConfig {
private final DynamicStringProperty listAutoScalingGroupsRoleName =
configInstance.getStringProperty(namespace + "listAutoScalingGroupsRoleName", "ListAutoScalingGroups");

private final DynamicStringProperty myUrl = configInstance.getStringProperty(namespace + "myUrl", null);

public DefaultEurekaServerConfig() {
init();
}
Expand Down Expand Up @@ -600,6 +602,11 @@ public boolean shouldBatchReplication() {
return configInstance.getBooleanProperty(namespace + "shouldBatchReplication", false).get();
}

@Override
public String getMyUrl() {
return myUrl.get();
}

@Override
public boolean shouldLogIdentityHeaders() {
return configInstance.getBooleanProperty(namespace + "auth.shouldLogIdentityHeaders", true).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ public interface EurekaServerConfig {
*/
boolean shouldBatchReplication();

/**
* Allows to configure URL which Eureka should treat as its own during replication. In some cases Eureka URLs don't
* match IP address or hostname (for example, when nodes are behind load balancers). Setting this parameter on each
* node to URLs of associated load balancers helps to avoid replication to the same node where event originally came
* to. Important: you need to configure the whole URL including scheme and path, like
* <code>http://eureka-node1.mydomain.com:8010/eureka/v2/</code>
* @return URL Eureka will treat as its own
*/
String getMyUrl();

/**
* Indicates whether the eureka server should log/metric clientAuthHeaders
* @return {@code true} if the clientAuthHeaders should be logged and/or emitted as metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ public static boolean isThisMe(String url) {
* replicate, false otherwise.
*/
public boolean isThisMyUrl(String url) {
final String myUrlConfigured = serverConfig.getMyUrl();
if (myUrlConfigured != null) {
return myUrlConfigured.equals(url);
}
return isInstanceURL(url, applicationInfoManager.getInfo());
}

Expand Down

0 comments on commit 01de9e5

Please sign in to comment.