Search in sources :

Example 1 with ServiceMethodInvoker

use of io.scalecube.services.methods.ServiceMethodInvoker in project scalecube by scalecube.

the class ServiceCall method requestBidirectional.

/**
 * Issues stream of service requests to service which returns stream of service messages back.
 *
 * @param publisher of service requests.
 * @param responseType type of responses (optional).
 * @return flux publisher of service responses.
 */
public Flux<ServiceMessage> requestBidirectional(Publisher<ServiceMessage> publisher, Type responseType) {
    return Flux.from(publisher).switchOnFirst((first, messages) -> {
        if (first.hasValue()) {
            ServiceMessage request = first.get();
            ServiceMethodInvoker methodInvoker;
            if (methodRegistry != null && (methodInvoker = methodRegistry.getInvoker(request.qualifier())) != null) {
                // local service
                return methodInvoker.invokeBidirectional(messages).map(this::throwIfError);
            } else {
                // remote service
                Objects.requireNonNull(transport, "[requestBidirectional] transport");
                return Mono.fromCallable(() -> serviceLookup(request)).flatMapMany(serviceReference -> transport.create(serviceReference).requestChannel(messages, responseType).map(this::throwIfError));
            }
        }
        return messages;
    });
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) ServiceMethodInvoker(io.scalecube.services.methods.ServiceMethodInvoker)

Aggregations

ServiceMessage (io.scalecube.services.api.ServiceMessage)1 ServiceMethodInvoker (io.scalecube.services.methods.ServiceMethodInvoker)1