use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.
the class Example3 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(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(seedAddress))).transport(RSocketServiceTransport::new).services(new BidiGreetingImpl()).startAwait();
// 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();
Mono.whenDelayError(seed.shutdown(), ms.shutdown()).block();
}
use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.
the class ServiceAuthRemoteTest method beforeAll.
@BeforeAll
static void beforeAll() {
StepVerifier.setDefaultTimeout(TIMEOUT);
principalMapper = authData -> new UserProfile(authData.get("name"), authData.get("role"));
service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator)).services(ServiceInfo.fromServiceInstance(new SecuredServiceImpl()).principalMapper(principalMapper).build()).startAwait();
serviceWithoutAuthenticator = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(RSocketServiceTransport::new).services(ServiceInfo.fromServiceInstance(new AnotherSecuredServiceImpl()).principalMapper(principalMapper).build()).startAwait();
partiallySecuredService = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator)).services(ServiceInfo.fromServiceInstance(new PartiallySecuredServiceImpl()).principalMapper(principalMapper).build()).startAwait();
}
use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.
the class PrincipalMapperAuthExample method main.
/**
* Main program.
*
* @param args arguments
*/
public static void main(String[] args) {
Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(ServiceInfo.fromServiceInstance(new SecuredServiceByApiKeyImpl()).principalMapper(PrincipalMapperAuthExample::apiKeyPrincipalMapper).build()).services(ServiceInfo.fromServiceInstance(new SecuredServiceByUserProfileImpl()).principalMapper(PrincipalMapperAuthExample::userProfilePrincipalMapper).build()).startAwait();
Microservices userProfileCaller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
String responseByUserProfile = userProfileCaller.call().api(SecuredServiceByUserProfile.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
System.err.println("### Received 'userProfileCaller' response: " + responseByUserProfile);
Microservices apiKeyCaller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
String responseByApiKey = apiKeyCaller.call().api(SecuredServiceByApiKey.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
System.err.println("### Received 'apiKeyCaller' response: " + responseByApiKey);
}
use of io.scalecube.services.transport.rsocket.RSocketServiceTransport in project scalecube by scalecube.
the class Example2 method main.
/**
* Main method.
*
* @param args - program arguments
*/
public static void main(String[] args) {
Microservices gateway = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(RSocketServiceTransport::new).startAwait();
final Address gatewayAddress = gateway.discovery().address();
Microservices service2Node = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(gatewayAddress))).transport(RSocketServiceTransport::new).services(new Service2Impl()).startAwait();
Microservices service1Node = Microservices.builder().discovery(endpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(endpoint)).membership(cfg -> cfg.seedMembers(gatewayAddress))).transport(RSocketServiceTransport::new).services(new Service1Impl()).startAwait();
gateway.call().api(Service1.class).remoteCallThenManyDelay(100).publishOn(Schedulers.parallel()).take(10).log("receive |").collectList().log("complete |").block();
Mono.whenDelayError(gateway.shutdown(), service1Node.shutdown(), service2Node.shutdown()).block();
}
use of io.scalecube.services.transport.rsocket.RSocketServiceTransport 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();
}
Aggregations