Search in sources :

Example 1 with GreetingsService

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

Aggregations

Address (io.scalecube.net.Address)1 Microservices (io.scalecube.services.Microservices)1 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)1 GreetingServiceImpl (io.scalecube.services.examples.helloworld.service.GreetingServiceImpl)1 GreetingsService (io.scalecube.services.examples.helloworld.service.api.GreetingsService)1 RSocketServiceTransport (io.scalecube.services.transport.rsocket.RSocketServiceTransport)1 WebsocketTransportFactory (io.scalecube.transport.netty.websocket.WebsocketTransportFactory)1 Mono (reactor.core.publisher.Mono)1