All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.scalecube.services.examples.helloworld.Example3 Maven / Gradle / Ivy

The newest version!
package io.scalecube.services.examples.helloworld;

import io.scalecube.services.Address;
import io.scalecube.services.Microservices;
import io.scalecube.services.Microservices.Context;
import io.scalecube.services.discovery.ScalecubeServiceDiscovery;
import io.scalecube.services.examples.helloworld.service.BidiGreetingImpl;
import io.scalecube.services.examples.helloworld.service.api.BidiGreetingService;
import io.scalecube.services.transport.rsocket.RSocketServiceTransport;
import io.scalecube.transport.netty.websocket.WebsocketTransportFactory;
import reactor.core.publisher.Flux;

/**
 * The Hello World project is a time-honored tradition in computer programming. It is a simple
 * exercise that gets you started when learning something new. Let’s get started with ScaleCube!
 *
 * 

the example starts 2 cluster member nodes. 1. seed is a member node and holds no services of * its own. 2. The microservices variable is a member that joins seed member and * provision BidiGreetingService instance. */ public class Example3 { /** * Start the example. * * @param args ignored */ public static void main(String[] args) { // ScaleCube Node with no members Microservices seed = Microservices.start( new Context() .discovery( serviceEndpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) .options(opts -> opts.metadata(serviceEndpoint))) .transport(RSocketServiceTransport::new)); final Address seedAddress = seed.discoveryAddress(); // Construct a ScaleCube node which joins the cluster hosting the Greeting Service Microservices ms = Microservices.start( new Context() .discovery( endpoint -> new ScalecubeServiceDiscovery() .transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())) .options(opts -> opts.metadata(endpoint)) .membership(cfg -> cfg.seedMembers(seedAddress.toString()))) .transport(RSocketServiceTransport::new) .services(new BidiGreetingImpl())); // Create service proxy BidiGreetingService service = seed.call().api(BidiGreetingService.class); // Execute the services and subscribe to service events service .greeting(Flux.fromArray(new String[] {"joe", "dan", "roni"})) .doOnNext(System.out::println) .blockLast(); seed.close(); ms.close(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy