Search in sources :

Example 16 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class Example1 method main.

/**
 * Main method.
 *
 * @param args - program 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();
    final Address gatewayAddress = gateway.discovery().address();
    Microservices service2Node = 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(new Service2Impl()).startAwait();
    Microservices service1Node = 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(new Service1Impl()).startAwait();
    gateway.call().api(Service1.class).manyDelay(100).publishOn(Schedulers.parallel()).take(10).log("receive     |").collectList().log("complete    |").block();
    Mono.whenDelayError(gateway.shutdown(), service1Node.shutdown(), service2Node.shutdown()).block();
}
Also used : RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Microservices(io.scalecube.services.Microservices) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) Schedulers(reactor.core.scheduler.Schedulers) Mono(reactor.core.publisher.Mono) Address(io.scalecube.net.Address) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Address(io.scalecube.net.Address) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices)

Example 17 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class Example1 method main.

/**
 * Start the example.
 *
 * @param args ignored
 */
public static void main(String[] args) {
    // ScaleCube Node with no members
    Microservices seed = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(RSocketServiceTransport::new).defaultContentType(// set explicit default data format
    PROTOSTUFF).startAwait();
    final Address seedAddress = seed.discovery().address();
    // Construct a ScaleCube node which joins the cluster hosting the Greeting Service
    Microservices ms = 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(new GreetingServiceImpl()).startAwait();
    seed.call().api(GreetingsService.class).sayHello("joe (on default dataFormat PROTOSTUFF)").subscribe(consumer -> System.out.println(consumer.message()));
    seed.call().contentType(JSON).api(GreetingsService.class).sayHello("alice (on JSON dataFormat)").subscribe(consumer -> System.out.println(consumer.message()));
    seed.call().contentType(OCTET_STREAM).api(GreetingsService.class).sayHello("bob (on java native Serializable/Externalizable dataFormat)").subscribe(consumer -> System.out.println(consumer.message()));
    seed.onShutdown().block();
    ms.onShutdown().block();
}
Also used : RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) GreetingServiceImpl(io.scalecube.services.examples.helloworld.service.GreetingServiceImpl) Microservices(io.scalecube.services.Microservices) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingsService(io.scalecube.services.examples.helloworld.service.api.GreetingsService) Address(io.scalecube.net.Address) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Address(io.scalecube.net.Address) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingServiceImpl(io.scalecube.services.examples.helloworld.service.GreetingServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices)

Example 18 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class ErrorFlowTest method initNodes.

@BeforeAll
public static void initNodes() {
    provider = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).transport(cfg -> cfg.port(PORT.incrementAndGet())).options(opts -> opts.metadata(endpoint))).transport(RSocketServiceTransport::new).services(new GreetingServiceImpl()).startAwait();
    final Address seedAddress = provider.discovery().address();
    consumer = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().membership(cfg -> cfg.seedMembers(seedAddress)).transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).transport(cfg -> cfg.port(PORT.incrementAndGet())).options(opts -> opts.metadata(endpoint))).transport(RSocketServiceTransport::new).startAwait();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) StepVerifier(reactor.test.StepVerifier) InternalServiceException(io.scalecube.services.exceptions.InternalServiceException) Publisher(org.reactivestreams.Publisher) GreetingResponse(io.scalecube.services.sut.GreetingResponse) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) ForbiddenException(io.scalecube.services.exceptions.ForbiddenException) ServiceUnavailableException(io.scalecube.services.exceptions.ServiceUnavailableException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) Mono.from(reactor.core.publisher.Mono.from) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) ServiceMessage(io.scalecube.services.api.ServiceMessage) BadRequestException(io.scalecube.services.exceptions.BadRequestException) Address(io.scalecube.net.Address) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Address(io.scalecube.net.Address) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 19 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class ServiceCallLocalTest method test_custom_error_mapper.

@Test
public void test_custom_error_mapper() {
    GreetingService service = new ServiceCall().errorMapper(message -> {
        throw new RuntimeException("custom error mapper");
    }).transport(new RSocketServiceTransport().start().block().clientTransport()).router(ServiceCallLocalTest::route).api(GreetingService.class);
    StepVerifier.create(service.exceptionRequest(new GreetingRequest())).expectErrorSatisfies(throwable -> {
        Assertions.assertEquals(RuntimeException.class, throwable.getClass());
        Assertions.assertEquals("custom error mapper", throwable.getMessage());
    }).verify(timeout);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) GREETING_THROWING_VOID_REQ(io.scalecube.services.TestRequests.GREETING_THROWING_VOID_REQ) StepVerifier(reactor.test.StepVerifier) GreetingResponse(io.scalecube.services.sut.GreetingResponse) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) GREETING_FAILING_VOID_REQ(io.scalecube.services.TestRequests.GREETING_FAILING_VOID_REQ) Duration(java.time.Duration) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) GreetingRequest(io.scalecube.services.sut.GreetingRequest) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) GREETING_REQUEST_TIMEOUT_REQ(io.scalecube.services.TestRequests.GREETING_REQUEST_TIMEOUT_REQ) GREETING_VOID_REQ(io.scalecube.services.TestRequests.GREETING_VOID_REQ) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) GREETING_NO_PARAMS_REQUEST(io.scalecube.services.TestRequests.GREETING_NO_PARAMS_REQUEST) ServiceException(io.scalecube.services.exceptions.ServiceException) EmptyGreetingResponse(io.scalecube.services.sut.EmptyGreetingResponse) GREETING_FAIL_REQ(io.scalecube.services.TestRequests.GREETING_FAIL_REQ) GREETING_EMPTY_REQUEST_RESPONSE(io.scalecube.services.TestRequests.GREETING_EMPTY_REQUEST_RESPONSE) ServiceRegistry(io.scalecube.services.registry.api.ServiceRegistry) Publisher(org.reactivestreams.Publisher) GREETING_ERROR_REQ(io.scalecube.services.TestRequests.GREETING_ERROR_REQ) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) NOT_FOUND_REQ(io.scalecube.services.TestRequests.NOT_FOUND_REQ) RoundRobinServiceRouter(io.scalecube.services.routing.RoundRobinServiceRouter) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Test(org.junit.jupiter.api.Test) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) GreetingService(io.scalecube.services.sut.GreetingService) Assertions(org.junit.jupiter.api.Assertions) 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) Collections(java.util.Collections) GreetingRequest(io.scalecube.services.sut.GreetingRequest) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) GreetingService(io.scalecube.services.sut.GreetingService) Test(org.junit.jupiter.api.Test)

Example 20 with RSocketServiceTransport

use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.

the class ServiceRegistryTest method test_delayed_listen_to_discovery_events.

@ParameterizedTest
@MethodSource("metadataCodecSource")
public void test_delayed_listen_to_discovery_events(MetadataCodec metadataCodec) {
    Sinks.Many<ServiceDiscoveryEvent> processor = Sinks.many().replay().all();
    List<Microservices> cluster = new CopyOnWriteArrayList<>();
    Microservices seed = Microservices.builder().discovery(defServiceDiscovery(metadataCodec)).transport(RSocketServiceTransport::new).services(new GreetingServiceImpl()).startAwait();
    cluster.add(seed);
    seed.listenDiscovery().subscribe(processor::tryEmitNext, processor::tryEmitError, processor::tryEmitComplete);
    Address seedAddress = seed.discovery().address();
    StepVerifier.create(processor.asFlux().onBackpressureBuffer()).then(() -> {
        Microservices ms1 = Microservices.builder().discovery(defServiceDiscovery(seedAddress, metadataCodec)).transport(RSocketServiceTransport::new).services(new GreetingServiceImpl(), new AnnotationServiceImpl()).startAwait();
        cluster.add(ms1);
    }).assertNext(event -> assertEquals(ENDPOINT_ADDED, event.type())).then(() -> {
        Microservices ms2 = Microservices.builder().discovery(defServiceDiscovery(seedAddress, metadataCodec)).transport(RSocketServiceTransport::new).services(new GreetingServiceImpl()).startAwait();
        cluster.add(ms2);
    }).assertNext(event -> assertEquals(ENDPOINT_ADDED, event.type())).thenCancel().verify(TIMEOUT);
    StepVerifier.create(seed.call().api(AnnotationService.class).serviceDiscoveryEventTypes()).assertNext(type -> assertEquals(ENDPOINT_ADDED, type)).assertNext(type -> assertEquals(ENDPOINT_ADDED, type)).thenCancel().verify(TIMEOUT);
    Mono.whenDelayError(cluster.stream().map(Microservices::shutdown).toArray(Mono[]::new)).block(TIMEOUT);
}
Also used : Sinks(reactor.core.publisher.Sinks) ENDPOINT_LEAVING(io.scalecube.services.discovery.api.ServiceDiscoveryEvent.Type.ENDPOINT_LEAVING) StepVerifier(reactor.test.StepVerifier) MetadataCodec(io.scalecube.cluster.metadata.MetadataCodec) JdkMetadataCodec(io.scalecube.cluster.metadata.JdkMetadataCodec) ENDPOINT_ADDED(io.scalecube.services.discovery.api.ServiceDiscoveryEvent.Type.ENDPOINT_ADDED) Duration(java.time.Duration) ServiceDiscoveryEvent(io.scalecube.services.discovery.api.ServiceDiscoveryEvent) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Address(io.scalecube.net.Address) MethodSource(org.junit.jupiter.params.provider.MethodSource) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) ENDPOINT_REMOVED(io.scalecube.services.discovery.api.ServiceDiscoveryEvent.Type.ENDPOINT_REMOVED) JacksonMetadataCodec(io.scalecube.cluster.codec.jackson.JacksonMetadataCodec) Mono(reactor.core.publisher.Mono) Arguments(org.junit.jupiter.params.provider.Arguments) AnnotationService(io.scalecube.services.sut.AnnotationService) AnnotationServiceImpl(io.scalecube.services.sut.AnnotationServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) ServiceDiscoveryFactory(io.scalecube.services.discovery.api.ServiceDiscoveryFactory) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Sinks(reactor.core.publisher.Sinks) Address(io.scalecube.net.Address) ServiceDiscoveryEvent(io.scalecube.services.discovery.api.ServiceDiscoveryEvent) AnnotationServiceImpl(io.scalecube.services.sut.AnnotationServiceImpl) GreetingServiceImpl(io.scalecube.services.sut.GreetingServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

RSocketServiceTransport (io.scalecube.services.transport.rsocket.RSocketServiceTransport)26 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)22 WebsocketTransportFactory (io.scalecube.transport.netty.websocket.WebsocketTransportFactory)22 Mono (reactor.core.publisher.Mono)18 Address (io.scalecube.net.Address)16 Microservices (io.scalecube.services.Microservices)13 Duration (java.time.Duration)12 Test (org.junit.jupiter.api.Test)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 ServiceMessage (io.scalecube.services.api.ServiceMessage)8 GreetingServiceImpl (io.scalecube.services.sut.GreetingServiceImpl)8 StepVerifier (reactor.test.StepVerifier)8 BeforeAll (org.junit.jupiter.api.BeforeAll)7 AfterAll (org.junit.jupiter.api.AfterAll)6 GreetingResponse (io.scalecube.services.sut.GreetingResponse)5 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 Publisher (org.reactivestreams.Publisher)5 ServiceInfo (io.scalecube.services.ServiceInfo)4 Authenticator (io.scalecube.services.auth.Authenticator)4