com.github.cherrythefatbunny.reactive.dubbo.extensions.proxyfactory.AbstractReactiveProxyInvoker Maven / Gradle / Ivy
The newest version!
package com.github.cherrythefatbunny.reactive.dubbo.extensions.proxyfactory;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.*;
import org.apache.dubbo.rpc.proxy.AbstractProxyInvoker;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import static com.github.cherrythefatbunny.reactive.dubbo.extensions.Constants.*;
/**
* Abstraction of reactive proxy invoker which will delegate consumer in provider side.
* @author cherry
*/
public abstract class AbstractReactiveProxyInvoker extends AbstractProxyInvoker {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractReactiveProxyInvoker.class);
protected final T proxy;
private final Class type;
private final URL url;
public AbstractReactiveProxyInvoker(T proxy, Class type, URL url) {
super(proxy, type, url);
this.proxy = proxy;
this.type = type;
this.url = url;
}
@Override
public Result invoke(Invocation invocation) throws RpcException {
String publisher = invocation.getAttachment(KEY_PUBLISHER_TYPE);
if(StringUtils.isBlank(publisher)) {
return super.invoke(invocation);
}
RpcContext rpcContext = RpcContext.getContext();
try {
Object obj = doInvoke(proxy, invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments());
Mono mono = null;
if(publisher.equals(VALUE_PUBLISHER_MONO)) {
mono = (Mono) obj;
} else if(publisher.equals(VALUE_PUBLISHER_FLUX)) {
Flux