use of com.tencent.polaris.client.pb.RoutingProto.Routing in project polaris-java by polarismesh.
the class ServiceDynamicRuleTest method before.
@Before
public void before() {
try {
namingServer = NamingServer.startNamingServer(10081);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
ServiceKey serviceKey = new ServiceKey(NAMESPACE_PRODUCTION, RULE_ROUTER_SERVICE);
InstanceParameter parameter = new InstanceParameter();
parameter.setWeight(100);
parameter.setHealthy(true);
parameter.setIsolated(false);
Map<String, String> metadata = new HashMap<>();
metadata.put("env", "base");
parameter.setMetadata(metadata);
namingServer.getNamingService().batchAddInstances(serviceKey, 10001, MATCH_META_COUNT, parameter);
parameter.setMetadata(null);
namingServer.getNamingService().batchAddInstances(serviceKey, 10010, 8, parameter);
Map<String, MatchString> data = new HashMap<>();
data.put("env", MatchString.newBuilder().setType(MatchStringType.EXACT).setValue(StringValue.newBuilder().setValue("base").build()).build());
Map<String, MatchString> srcData = new HashMap<>();
srcData.put("uid", MatchString.newBuilder().setType(MatchStringType.EXACT).setValue(StringValue.newBuilder().setValue("144115217417489762").build()).build());
Routing routing = Routing.newBuilder().addInbounds(Route.newBuilder().addDestinations(Destination.newBuilder().putAllMetadata(data).setWeight(UInt32Value.newBuilder().setValue(100).build()).build()).addSources(Source.newBuilder().setNamespace(StringValue.newBuilder().setValue("*").build()).setService(StringValue.newBuilder().setValue("*").build()).putAllMetadata(srcData).build()).build()).build();
namingServer.getNamingService().setRouting(serviceKey, routing);
}
use of com.tencent.polaris.client.pb.RoutingProto.Routing in project polaris-java by polarismesh.
the class RoutingCacheHandler method messageToCacheValue.
@Override
public RegistryCacheValue messageToCacheValue(RegistryCacheValue oldValue, Object newValue, boolean isCacheLoaded) {
DiscoverResponse discoverResponse = (DiscoverResponse) newValue;
Routing routing = discoverResponse.getRouting();
String revision = "";
if (null != routing) {
revision = routing.getRevision().getValue();
}
return new ServiceRuleByProto(routing, revision, isCacheLoaded, getTargetEventType());
}
Aggregations