|
7 | 7 | import io.scalecube.config.source.SystemEnvironmentConfigSource; |
8 | 8 | import io.scalecube.config.source.SystemPropertiesConfigSource; |
9 | 9 | import io.scalecube.net.Address; |
| 10 | +import io.scalecube.runners.Runners; |
10 | 11 | import io.scalecube.services.Microservices; |
11 | 12 | import io.scalecube.services.ServiceEndpoint; |
12 | 13 | import io.scalecube.services.discovery.ScalecubeServiceDiscovery; |
@@ -51,29 +52,32 @@ public static void main(String[] args) { |
51 | 52 | .orElse(Runtime.getRuntime().availableProcessors()); |
52 | 53 | LOGGER.info("Number of worker threads: " + numOfThreads); |
53 | 54 |
|
54 | | - Microservices.builder() |
55 | | - .discovery(endpoint -> serviceDiscovery(endpoint, config)) |
56 | | - .transport( |
57 | | - () -> |
58 | | - new RSocketServiceTransport() |
59 | | - .tcpClient( |
60 | | - loopResources -> |
61 | | - TcpClient.newConnection() |
62 | | - .runOn(loopResources) |
63 | | - .wiretap(false) |
64 | | - .noProxy() |
65 | | - .noSSL()) |
66 | | - .tcpServer( |
67 | | - loopResources -> |
68 | | - TcpServer.create() |
69 | | - .wiretap(false) |
70 | | - .port(config.servicePort()) |
71 | | - .runOn(loopResources) |
72 | | - .noSSL())) |
73 | | - .services(new BenchmarkServiceImpl(), new GreetingServiceImpl()) |
74 | | - .startAwait() |
75 | | - .onShutdown() |
76 | | - .block(); |
| 55 | + Microservices microservices = |
| 56 | + Microservices.builder() |
| 57 | + .discovery(endpoint -> serviceDiscovery(endpoint, config)) |
| 58 | + .transport( |
| 59 | + () -> |
| 60 | + new RSocketServiceTransport() |
| 61 | + .tcpClient( |
| 62 | + loopResources -> |
| 63 | + TcpClient.newConnection() |
| 64 | + .runOn(loopResources) |
| 65 | + .wiretap(false) |
| 66 | + .noProxy() |
| 67 | + .noSSL()) |
| 68 | + .tcpServer( |
| 69 | + loopResources -> |
| 70 | + TcpServer.create() |
| 71 | + .wiretap(false) |
| 72 | + .port(config.servicePort()) |
| 73 | + .runOn(loopResources) |
| 74 | + .noSSL())) |
| 75 | + .services(new BenchmarkServiceImpl(), new GreetingServiceImpl()) |
| 76 | + .startAwait(); |
| 77 | + |
| 78 | + Runners.onShutdown(() -> microservices.shutdown().subscribe()); |
| 79 | + |
| 80 | + microservices.onShutdown().block(); |
77 | 81 | } |
78 | 82 |
|
79 | 83 | private static ServiceDiscovery serviceDiscovery(ServiceEndpoint endpoint, Config config) { |
|
0 commit comments