use of io.scalecube.services.routings.sut.CanaryService in project scalecube by scalecube.
the class RoutersTest method test_remote_service_tags.
@Test
public void test_remote_service_tags() throws Exception {
CanaryService service = gateway.call().router(Routers.getRouter(WeightedRandomRouter.class)).api(CanaryService.class);
Thread.sleep(1000);
AtomicInteger serviceBCount = new AtomicInteger(0);
int n = (int) 1e3;
Flux.range(0, n).flatMap(i -> service.greeting(new GreetingRequest("joe"))).filter(response -> response.getResult().contains("SERVICE_B_TALKING")).doOnNext(response -> serviceBCount.incrementAndGet()).blockLast(Duration.ofSeconds(3));
System.out.println("Service B was called: " + serviceBCount.get() + " times out of " + n);
assertTrue((serviceBCount.doubleValue() / n) > 0.5, "Service B's Weight=0.9; more than half of invocations have to be routed to Service B");
}
use of io.scalecube.services.routings.sut.CanaryService in project scalecube by scalecube.
the class ServiceTagsExample method main.
/**
* Main runner.
*
* @param args arguments
*/
public static void main(String[] args) {
Microservices gateway = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(RSocketServiceTransport::new).startAwait();
Address seedAddress = gateway.discovery().address();
Microservices services1 = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(seedAddress))).transport(RSocketServiceTransport::new).services(ServiceInfo.fromServiceInstance(new GreetingServiceImplA()).tag("Weight", "0.3").build()).startAwait();
Microservices services2 = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(seedAddress))).transport(RSocketServiceTransport::new).services(ServiceInfo.fromServiceInstance(new GreetingServiceImplB()).tag("Weight", "0.7").build()).startAwait();
CanaryService service = gateway.call().router(WeightedRandomRouter.class).api(CanaryService.class);
for (int i = 0; i < 10; i++) {
Mono.from(service.greeting(new GreetingRequest("joe"))).doOnNext(success -> {
success.getResult().startsWith("B");
System.out.println(success);
});
}
}
Aggregations