Commit 39d592bc by Nepxion

增强路由功能

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