@@ -61,27 +61,48 @@ The example provisions 2 cluster nodes and making a remote interaction.
61613 . finally from seed node - create a proxy by the GreetingService api and send a greeting request.
6262
6363``` java
64- // 1. ScaleCube Node node with no members
65- Microservices seed = Microservices . builder(). startAwait();
66-
67- // 2. Construct a ScaleCube node which joins the cluster hosting the Greeting Service
68- Microservices microservices =
69- Microservices . builder()
70- .discovery(
71- self - >
72- new ScalecubeServiceDiscovery (self)
73- .options(opts - > opts. seedMembers(toAddress(seed. discovery(). address()))))
74- .transport(ServiceTransports :: rsocketServiceTransport)
75- .services(new GreetingServiceImpl ())
76- .startAwait();
77-
78- // 3. Create service proxy
79- GreetingsService service = seed. call(). api(GreetingsService . class);
80-
81- // Execute the services and subscribe to service events
82- service. sayHello(" joe" ). subscribe(consumer - > {
83- System . out. println(consumer. message());
84- });
64+ // service definition
65+ @Service (" io.scalecube.Greetings" )
66+ public interface GreetingsService {
67+ @ServiceMethod (" sayHello" )
68+ Mono<Greeting > sayHello (String name );
69+ }
70+
71+ // service implementation
72+ public class GreetingServiceImpl implements GreetingsService {
73+ @Override
74+ public Mono<Greeting > sayHello (String name ) {
75+ return Mono . just(new Greeting (" Nice to meet you " + name + " and welcome to ScaleCube" ));
76+ }
77+ }
78+
79+ // 1. ScaleCube Node node with no members (container 1)
80+ Microservices seed =
81+ Microservices . builder()
82+ .discovery(" seed" , ScalecubeServiceDiscovery :: new )
83+ .transport(RSocketServiceTransport :: new )
84+ .startAwait();
85+
86+ // get the address of the seed member - will be used to join any other members to the cluster.
87+ final Address seedAddress = seed. discovery(" seed" ). address();
88+
89+ // 2. Construct a ScaleCube node which joins the cluster hosting the Greeting Service (container 2)
90+ Microservices serviceNode = Microservices . builder()
91+ .discovery(" seed" , ep - > new ScalecubeServiceDiscovery (ep)
92+ .membership(cfg - > cfg. seedMembers(seedAddress)))
93+ .transport(RSocketServiceTransport :: new )
94+ .services(new GreetingServiceImpl ())
95+ .startAwait();
96+
97+ // 3. Create service proxy (can be created from any node or container in the cluster)
98+ // 4. Execute the services and subscribe to service events
99+ seed. call(). api(GreetingsService . class)
100+ .sayHello(" joe" ). subscribe(consumer - > {
101+ System . out. println(consumer. message());
102+ });
103+
104+ Mono . whenDelayError(seed. shutdown(), serviceNode. shutdown())
105+ .block();
85106```
86107
87108Basic Service Example :
0 commit comments