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;
});
}
Aggregations