Commit 39d592bc by Nepxion

增强路由功能

parent 4ae12018
...@@ -22,7 +22,6 @@ public class DiscoveryConstant { ...@@ -22,7 +22,6 @@ public class DiscoveryConstant {
public static final String SPRING_APPLICATION_NAME = "spring.application.name"; public static final String SPRING_APPLICATION_NAME = "spring.application.name";
public static final String GROUP = "group"; public static final String GROUP = "group";
public static final String REGION = "region"; public static final String REGION = "region";
public static final String ZONE = "zone";
public static final String SERVICE_ID = "serviceId"; public static final String SERVICE_ID = "serviceId";
public static final String HOST = "host"; public static final String HOST = "host";
public static final String PORT = "port"; public static final String PORT = "port";
......
...@@ -24,6 +24,7 @@ public class RouterEntity implements Serializable { ...@@ -24,6 +24,7 @@ public class RouterEntity implements Serializable {
private String serviceId; private String serviceId;
private String version; private String version;
private String region;
private String host; private String host;
private int port; private int port;
private int weight = -1; private int weight = -1;
...@@ -48,6 +49,14 @@ public class RouterEntity implements Serializable { ...@@ -48,6 +49,14 @@ public class RouterEntity implements Serializable {
this.version = version; this.version = version;
} }
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getHost() { public String getHost() {
return host; return host;
} }
......
...@@ -205,6 +205,10 @@ public class RouterTopology extends AbstractTopology { ...@@ -205,6 +205,10 @@ public class RouterTopology extends AbstractTopology {
stringBuilder.append("\n [V").append(routerEntity.getVersion()).append("]"); stringBuilder.append("\n [V").append(routerEntity.getVersion()).append("]");
} }
if (StringUtils.isNotEmpty(routerEntity.getRegion())) {
stringBuilder.append("\n [Region=").append(routerEntity.getRegion()).append("]");
}
Map<String, String> customMap = routerEntity.getCustomMap(); Map<String, String> customMap = routerEntity.getCustomMap();
if (MapUtils.isNotEmpty(customMap)) { if (MapUtils.isNotEmpty(customMap)) {
for (Map.Entry<String, String> entry : customMap.entrySet()) { for (Map.Entry<String, String> entry : customMap.entrySet()) {
......
...@@ -123,15 +123,21 @@ public class RouterEndpoint { ...@@ -123,15 +123,21 @@ public class RouterEndpoint {
public RouterEntity getRouterEntity() { public RouterEntity getRouterEntity() {
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
String version = pluginAdapter.getVersion(); String version = pluginAdapter.getVersion();
String region = pluginAdapter.getRegion();
String host = pluginAdapter.getHost(); String host = pluginAdapter.getHost();
int port = pluginAdapter.getPort(); int port = pluginAdapter.getPort();
int weight = getWeight(serviceId, version);
Map<String, String> customMap = getCustomMap(serviceId);
String contextPath = pluginAdapter.getContextPath(); String contextPath = pluginAdapter.getContextPath();
RouterEntity routerEntity = new RouterEntity(); RouterEntity routerEntity = new RouterEntity();
routerEntity.setServiceId(serviceId); routerEntity.setServiceId(serviceId);
routerEntity.setVersion(version); routerEntity.setVersion(version);
routerEntity.setRegion(region);
routerEntity.setHost(host); routerEntity.setHost(host);
routerEntity.setPort(port); routerEntity.setPort(port);
routerEntity.setWeight(weight);
routerEntity.setCustomMap(customMap);
routerEntity.setContextPath(contextPath); routerEntity.setContextPath(contextPath);
return routerEntity; return routerEntity;
...@@ -155,6 +161,7 @@ public class RouterEndpoint { ...@@ -155,6 +161,7 @@ public class RouterEndpoint {
Map<String, String> metadata = instance.getMetadata(); Map<String, String> metadata = instance.getMetadata();
String serviceId = instance.getServiceId().toLowerCase(); String serviceId = instance.getServiceId().toLowerCase();
String version = metadata.get(DiscoveryConstant.VERSION); String version = metadata.get(DiscoveryConstant.VERSION);
String region = metadata.get(DiscoveryConstant.REGION);
String host = instance.getHost(); String host = instance.getHost();
int port = instance.getPort(); int port = instance.getPort();
int weight = getWeight(routeServiceId, version); int weight = getWeight(routeServiceId, version);
...@@ -164,6 +171,7 @@ public class RouterEndpoint { ...@@ -164,6 +171,7 @@ public class RouterEndpoint {
RouterEntity routerEntity = new RouterEntity(); RouterEntity routerEntity = new RouterEntity();
routerEntity.setServiceId(serviceId); routerEntity.setServiceId(serviceId);
routerEntity.setVersion(version); routerEntity.setVersion(version);
routerEntity.setRegion(region);
routerEntity.setHost(host); routerEntity.setHost(host);
routerEntity.setPort(port); routerEntity.setPort(port);
routerEntity.setWeight(weight); routerEntity.setWeight(weight);
......
...@@ -143,6 +143,11 @@ public abstract class AbstractPluginAdapter implements PluginAdapter { ...@@ -143,6 +143,11 @@ public abstract class AbstractPluginAdapter implements PluginAdapter {
} }
@Override @Override
public String getRegion() {
return getMetadata().get(DiscoveryConstant.REGION);
}
@Override
public String getServerVersion(Server server) { public String getServerVersion(Server server) {
return getServerMetadata(server).get(DiscoveryConstant.VERSION); return getServerMetadata(server).get(DiscoveryConstant.VERSION);
} }
......
...@@ -49,6 +49,8 @@ public interface PluginAdapter { ...@@ -49,6 +49,8 @@ public interface PluginAdapter {
void clearDynamicRule(); void clearDynamicRule();
String getRegion();
Map<String, String> getServerMetadata(Server server); Map<String, String> getServerMetadata(Server server);
String getServerVersion(Server server); String getServerVersion(Server server);
......
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