码迷,mamicode.com
首页 > 其他好文 > 详细

dubbo 远程调用

时间:2019-11-05 00:48:11      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:exp   ret   info   get   spl   inf   ignore   map   change   

记得服务暴露的时候createServer()里 server = Exchangers.bind(url, requestHandler);

requestHandler在DubboProtocol里的实现如下:

 private ExchangeHandler requestHandler = new ExchangeHandlerAdapter() {

        @Override
        public Object reply(ExchangeChannel channel, Object message) throws RemotingException {
            if (message instanceof Invocation) {
                Invocation inv = (Invocation) message;
                Invoker<?> invoker = getInvoker(channel, inv);
                // need to consider backward-compatibility if it‘s a callback
                if (Boolean.TRUE.toString().equals(inv.getAttachments().get(IS_CALLBACK_SERVICE_INVOKE))) {
                    String methodsStr = invoker.getUrl().getParameters().get("methods");
                    boolean hasMethod = false;
                    if (methodsStr == null || methodsStr.indexOf(",") == -1) {
                        hasMethod = inv.getMethodName().equals(methodsStr);
                    } else {
                        String[] methods = methodsStr.split(",");
                        for (String method : methods) {
                            if (inv.getMethodName().equals(method)) {
                                hasMethod = true;
                                break;
                            }
                        }
                    }
                    if (!hasMethod) {
                        logger.warn(new IllegalStateException("The methodName " + inv.getMethodName()
                                + " not found in callback service interface ,invoke will be ignored."
                                + " please update the api interface. url is:"
                                + invoker.getUrl()) + " ,invocation is :" + inv);
                        return null;
                    }
                }
                RpcContext.getContext().setRemoteAddress(channel.getRemoteAddress());
                return invoker.invoke(inv);
            }
            throw new RemotingException(channel, "Unsupported request: "
                    + (message == null ? null : (message.getClass().getName() + ": " + message))
                    + ", channel: consumer: " + channel.getRemoteAddress() + " --> provider: " + channel.getLocalAddress());
        }

 

技术图片

 

 

其中getInvoker()会去AbstractProtocol里的exporterMap通过serviceKey(facade.EchoService:20880)得到DubboExporter实例,最后得到RegistryProtocol$InvokerDelegete实例返回,最后调用inoker()方法,总结了下各invoker和export的持有关系如下:

 

 

技术图片

 

 

 

 

 

技术图片

 

 

 

dubbo 远程调用

标签:exp   ret   info   get   spl   inf   ignore   map   change   

原文地址:https://www.cnblogs.com/lccsblog/p/11795858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!