Search in sources :

Example 1 with GreetingServiceImpl

use of io.scalecube.services.examples.helloworld.service.GreetingServiceImpl in project scalecube by scalecube.

the class Example2 method main.

/**
 * Start the example.
 *
 * @param args ignored
 */
public static void main(String[] args) {
    // ScaleCube Node node with no members
    Microservices seed = Microservices.builder().discovery("seed", serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(RSocketServiceTransport::new).startAwait();
    // Construct a ScaleCube node which joins the cluster hosting the Greeting Service
    final Address seedAddress = seed.discovery().address();
    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();
    // Create a proxy to the seed service node
    ServiceCall service = seed.call();
    // Create a ServiceMessage request with service qualifier and data
    ServiceMessage request = ServiceMessage.builder().qualifier(SERVICE_QUALIFIER).data("joe").build();
    // Execute the Greeting Service to emit a single Greeting response
    Publisher<ServiceMessage> publisher = service.requestOne(request, Greeting.class);
    // Convert the Publisher using the Mono API which ensures it will emit 0 or 1 item.
    Mono.from(publisher).subscribe(consumer -> {
        // handle service response
        Greeting greeting = consumer.data();
        System.out.println(greeting.message());
    });
    Mono.whenDelayError(seed.shutdown(), ms.shutdown()).block();
}
Also used : RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) GreetingServiceImpl(io.scalecube.services.examples.helloworld.service.GreetingServiceImpl) Greeting(io.scalecube.services.examples.helloworld.service.api.Greeting) Microservices(io.scalecube.services.Microservices) ServiceCall(io.scalecube.services.ServiceCall) Publisher(org.reactivestreams.Publisher) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) ServiceMessage(io.scalecube.services.api.ServiceMessage) Mono(reactor.core.publisher.Mono) Address(io.scalecube.net.Address) Greeting(io.scalecube.services.examples.helloworld.service.api.Greeting) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) ServiceMessage(io.scalecube.services.api.ServiceMessage) ServiceCall(io.scalecube.services.ServiceCall) 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 2 with GreetingServiceImpl

use of io.scalecube.services.examples.helloworld.service.GreetingServiceImpl 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).startAwait();
    final Address seedAddress = seed.discovery().address();
    // Construct a ScaleCube node which joins the cluster hosting the Greeting Service
    Microservices ms = Microservices.builder().discovery("ms", 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();
    // Create service proxy
    GreetingsService service = seed.call().api(GreetingsService.class);
    // Execute the services and subscribe to service events
    service.sayHello("joe").subscribe(consumer -> System.out.println(consumer.message()));
    Mono.whenDelayError(seed.shutdown(), ms.shutdown()).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) Mono(reactor.core.publisher.Mono) 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) GreetingsService(io.scalecube.services.examples.helloworld.service.api.GreetingsService) GreetingServiceImpl(io.scalecube.services.examples.helloworld.service.GreetingServiceImpl) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices)

Example 3 with GreetingServiceImpl

use of io.scalecube.services.examples.helloworld.service.GreetingServiceImpl 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)

Aggregations

Address (io.scalecube.net.Address)3 Microservices (io.scalecube.services.Microservices)3 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)3 GreetingServiceImpl (io.scalecube.services.examples.helloworld.service.GreetingServiceImpl)3 RSocketServiceTransport (io.scalecube.services.transport.rsocket.RSocketServiceTransport)3 WebsocketTransportFactory (io.scalecube.transport.netty.websocket.WebsocketTransportFactory)3 GreetingsService (io.scalecube.services.examples.helloworld.service.api.GreetingsService)2 Mono (reactor.core.publisher.Mono)2 ServiceCall (io.scalecube.services.ServiceCall)1 ServiceMessage (io.scalecube.services.api.ServiceMessage)1 Greeting (io.scalecube.services.examples.helloworld.service.api.Greeting)1 Publisher (org.reactivestreams.Publisher)1