use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.
the class ServiceLocalTest method test_local_bidi_greeting_message_expect_NotAuthorized.
@Test
public void test_local_bidi_greeting_message_expect_NotAuthorized() {
// get a proxy to the service api.
GreetingService service = createProxy(microservices);
Sinks.Many<GreetingRequest> requests = Sinks.many().multicast().directBestEffort();
// call the service.
Flux<GreetingResponse> responses = service.bidiGreetingNotAuthorizedMessage(requests.asFlux().onBackpressureBuffer().map(request -> ServiceMessage.builder().data(request).build())).map(ServiceMessage::data);
StepVerifier.create(responses).then(() -> requests.emitNext(new GreetingRequest("joe-1"), FAIL_FAST)).expectErrorMessage("Not authorized").verify(Duration.ofSeconds(3));
}
use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.
the class ServiceRemoteTest method test_remote_greeting_message.
@Test
void test_remote_greeting_message() {
GreetingService service = createProxy();
ServiceMessage request = ServiceMessage.builder().data(new GreetingRequest("joe")).build();
// using proxy
StepVerifier.create(service.greetingMessage(request)).assertNext(message -> {
assertEquals(GreetingResponse.class, message.data().getClass());
GreetingResponse resp = message.data();
assertEquals("1", resp.sender());
assertEquals("hello to: joe", resp.getResult());
}).expectComplete().verify(TIMEOUT);
StepVerifier.create(service.greetingMessage2(request)).assertNext(resp -> {
assertEquals("1", resp.sender());
assertEquals("hello to: joe", resp.getResult());
}).expectComplete().verify(TIMEOUT);
// using serviceCall directly
ServiceCall serviceCall = gateway.call();
StepVerifier.create(serviceCall.requestOne(ServiceMessage.from(request).qualifier("v1/greetings/greetingMessage").build(), GreetingResponse.class)).assertNext(message -> {
assertEquals(GreetingResponse.class, message.data().getClass());
GreetingResponse resp = message.data();
assertEquals("1", resp.sender());
assertEquals("hello to: joe", resp.getResult());
}).expectComplete().verify(TIMEOUT);
StepVerifier.create(serviceCall.requestOne(ServiceMessage.from(request).qualifier("v1/greetings/greetingMessage2").build(), GreetingResponse.class)).assertNext(message -> {
assertEquals(GreetingResponse.class, message.data().getClass());
GreetingResponse resp = message.data();
assertEquals("1", resp.sender());
assertEquals("hello to: joe", resp.getResult());
}).expectComplete().verify(TIMEOUT);
}
use of io.scalecube.services.api.ServiceMessage 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.api.ServiceMessage in project scalecube by scalecube.
the class GreetingServiceImpl method emptyGreetingMessage.
@Override
public Mono<ServiceMessage> emptyGreetingMessage(ServiceMessage request) {
EmptyGreetingRequest greetingRequest = request.data();
ServiceMessage response = ServiceMessage.from(request).data(new EmptyGreetingResponse()).build();
return Mono.just(response);
}
use of io.scalecube.services.api.ServiceMessage in project scalecube by scalecube.
the class CompositeProfileAuthExample 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(call -> Collections.singletonList(ServiceInfo.fromServiceInstance(new SecuredServiceByCompositeProfileImpl()).authenticator(compositeAuthenticator()).build())).startAwait();
Microservices caller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
ServiceMessage response = caller.call().requestOne(ServiceMessage.builder().qualifier("securedServiceByCompositeProfile/hello").header("userProfile.name", "SEGA").header("userProfile.role", "ADMIN").data("hello world").build(), String.class).block(Duration.ofSeconds(3));
System.err.println("### Received 'caller' response: " + response.data());
}
Aggregations