use of io.scalecube.services.examples.helloworld.service.api.Greeting 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();
}
use of io.scalecube.services.examples.helloworld.service.api.Greeting in project scalecube by scalecube.
the class CompositeDiscoveryExample method main.
/**
* Main program.
*
* @param args arguments
*/
public static void main(String[] args) {
Microservices seed1 = Microservices.builder().discovery("seed1", serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint)).options(opts -> opts.memberAlias("seed1"))).transport(RSocketServiceTransport::new).startAwait();
Microservices seed2 = Microservices.builder().discovery("seed2", serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint)).options(opts -> opts.memberAlias("seed2"))).transport(RSocketServiceTransport::new).startAwait();
final Address seed1Address = seed1.discovery("seed1").address();
final Address seed2Address = seed2.discovery("seed2").address();
Microservices ms1 = Microservices.builder().discovery("ms1", endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).options(opts -> opts.memberAlias("ms1")).membership(cfg -> cfg.seedMembers(seed1Address))).transport(RSocketServiceTransport::new).services(new GreetingServiceImpl1()).startAwait();
Microservices ms2 = Microservices.builder().discovery("ms2", endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).options(opts -> opts.memberAlias("ms2")).membership(cfg -> cfg.seedMembers(seed2Address))).transport(RSocketServiceTransport::new).services(new GreetingServiceImpl2()).startAwait();
Microservices compositeMs = Microservices.builder().discovery("domain1", endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).options(opts -> opts.memberAlias("domain1")).membership(cfg -> cfg.seedMembers(seed1Address))).discovery("domain2", endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).options(opts -> opts.memberAlias("domain2")).membership(cfg -> cfg.seedMembers(seed2Address))).transport(RSocketServiceTransport::new).startAwait();
Greeting greeting1 = compositeMs.call().api(GreetingsService1.class).sayHello("hello one").block();
System.err.println("This is response from GreetingsService1: " + greeting1.message());
Greeting greeting2 = compositeMs.call().api(GreetingsService2.class).sayHello("hello two").block();
System.err.println("This is response from GreetingsService2: " + greeting2.message());
}
Aggregations