Search in sources :

Example 1 with GreetingServiceImplA

use of io.scalecube.services.routings.sut.GreetingServiceImplA in project scalecube by scalecube.

the class RoutersTest method setup.

@BeforeAll
public static void setup() {
    gateway = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(RSocketServiceTransport::new).startAwait();
    gatewayAddress = gateway.discovery().address();
    // Create microservices instance cluster.
    provider1 = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(gatewayAddress))).transport(RSocketServiceTransport::new).services(ServiceInfo.fromServiceInstance(new GreetingServiceImpl(1)).tag("ONLYFOR", "joe").tag("SENDER", "1").build(), ServiceInfo.fromServiceInstance(new GreetingServiceImplA()).tag("Weight", "0.1").build()).startAwait();
    // Create microservices instance cluster.
    provider2 = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(gatewayAddress))).transport(RSocketServiceTransport::new).services(ServiceInfo.fromServiceInstance(new GreetingServiceImpl(2)).tag("ONLYFOR", "fransin").tag("SENDER", "2").build(), ServiceInfo.fromServiceInstance(new GreetingServiceImplB()).tag("Weight", "0.9").build()).startAwait();
    TagService tagService = input -> input.map(String::toUpperCase);
    provider3 = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(gatewayAddress))).transport(RSocketServiceTransport::new).services(ServiceInfo.fromServiceInstance(tagService).tag("tagB", "bb").tag("tagC", "c").build()).startAwait();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) GreetingServiceImplB(io.scalecube.services.routings.sut.GreetingServiceImplB) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) GreetingServiceImplA(io.scalecube.services.routings.sut.GreetingServiceImplA) DummyRouter(io.scalecube.services.routings.sut.DummyRouter) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) GreetingResponse(io.scalecube.services.sut.GreetingResponse) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) RandomServiceRouter(io.scalecube.services.routing.RandomServiceRouter) GREETING_REQUEST_REQ2(io.scalecube.services.TestRequests.GREETING_REQUEST_REQ2) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) ServiceCall(io.scalecube.services.ServiceCall) Duration(java.time.Duration) Map(java.util.Map) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingRequest(io.scalecube.services.sut.GreetingRequest) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Address(io.scalecube.net.Address) ServiceReference(io.scalecube.services.ServiceReference) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) CanaryService(io.scalecube.services.routings.sut.CanaryService) ServiceInfo(io.scalecube.services.ServiceInfo) Mono(reactor.core.publisher.Mono) TagService(io.scalecube.services.routings.sut.TagService) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Routers(io.scalecube.services.routing.Routers) Flux(reactor.core.publisher.Flux) Microservices(io.scalecube.services.Microservices) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Reflect(io.scalecube.services.Reflect) GREETING_REQUEST_REQ(io.scalecube.services.TestRequests.GREETING_REQUEST_REQ) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) Optional(java.util.Optional) ServiceMessage(io.scalecube.services.api.ServiceMessage) BaseTest(io.scalecube.services.BaseTest) WeightedRandomRouter(io.scalecube.services.routings.sut.WeightedRandomRouter) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) TagService(io.scalecube.services.routings.sut.TagService) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) GreetingServiceImplA(io.scalecube.services.routings.sut.GreetingServiceImplA) GreetingServiceImplB(io.scalecube.services.routings.sut.GreetingServiceImplB) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with GreetingServiceImplA

use of io.scalecube.services.routings.sut.GreetingServiceImplA 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);
        });
    }
}
Also used : GreetingServiceImplB(io.scalecube.services.routings.sut.GreetingServiceImplB) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) CanaryService(io.scalecube.services.routings.sut.CanaryService) GreetingServiceImplA(io.scalecube.services.routings.sut.GreetingServiceImplA) Microservices(io.scalecube.services.Microservices) ServiceInfo(io.scalecube.services.ServiceInfo) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingRequest(io.scalecube.services.sut.GreetingRequest) Mono(reactor.core.publisher.Mono) Address(io.scalecube.net.Address) WeightedRandomRouter(io.scalecube.services.routings.sut.WeightedRandomRouter) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Address(io.scalecube.net.Address) WeightedRandomRouter(io.scalecube.services.routings.sut.WeightedRandomRouter) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingRequest(io.scalecube.services.sut.GreetingRequest) CanaryService(io.scalecube.services.routings.sut.CanaryService) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) GreetingServiceImplA(io.scalecube.services.routings.sut.GreetingServiceImplA) Microservices(io.scalecube.services.Microservices) GreetingServiceImplB(io.scalecube.services.routings.sut.GreetingServiceImplB)

Aggregations

Address (io.scalecube.net.Address)2 Microservices (io.scalecube.services.Microservices)2 ServiceInfo (io.scalecube.services.ServiceInfo)2 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)2 CanaryService (io.scalecube.services.routings.sut.CanaryService)2 GreetingServiceImplA (io.scalecube.services.routings.sut.GreetingServiceImplA)2 GreetingServiceImplB (io.scalecube.services.routings.sut.GreetingServiceImplB)2 WeightedRandomRouter (io.scalecube.services.routings.sut.WeightedRandomRouter)2 GreetingRequest (io.scalecube.services.sut.GreetingRequest)2 RSocketServiceTransport (io.scalecube.services.transport.rsocket.RSocketServiceTransport)2 WebsocketTransportFactory (io.scalecube.transport.netty.websocket.WebsocketTransportFactory)2 Mono (reactor.core.publisher.Mono)2 BaseTest (io.scalecube.services.BaseTest)1 Reflect (io.scalecube.services.Reflect)1 ServiceCall (io.scalecube.services.ServiceCall)1 ServiceReference (io.scalecube.services.ServiceReference)1 GREETING_REQUEST_REQ (io.scalecube.services.TestRequests.GREETING_REQUEST_REQ)1 GREETING_REQUEST_REQ2 (io.scalecube.services.TestRequests.GREETING_REQUEST_REQ2)1 ServiceMessage (io.scalecube.services.api.ServiceMessage)1 RandomServiceRouter (io.scalecube.services.routing.RandomServiceRouter)1