13 - 本地服務引用(Injvm)

騰一部分筆記到csdn

 

1. 概述

Dubbo 服務引用,和 Dubbo 服務暴露一樣有兩種方式:
 
// 推薦
<dubbo:reference scope="local" />
// 不推薦使用,準備廢棄
<dubbo:reference injvm="true" />
<dubbo:reference scope="remote" />
 

2. createProxy

本地引用服務的順序圖如下:
 
 
在 4* - API 配置(三)之服務消費者 一文中,我們看到 ReferenceConfig#init() 方法中,會在配置初始化完成後,調用 #createProxy(map) 方法生成對象。本地引用時
invoker = refprotocol.refer(interfaceClass, url); //獲取invoker,從這句開始分析
 
invoker = refprotocol.refer(interfaceClass, url); //獲取invoker
    -> return new InjvmInvoker<T>(serviceType, url, url.getServiceKey(), exporterMap);
 
        @Override
        public Result doInvoke(Invocation invocation) throws Throwable {
            // 獲得 Exporter 對象
            Exporter<?> exporter= InjvmProtocol.getExporter(exporterMap, getUrl());
            if (exporter == null) {
                throw new RpcException("Service ["+ key + "] not found.");
            }
            // 設置服務提供者地址爲本地
            RpcContext.getContext().setRemoteAddress(NetUtils.LOCALHOST, 0);
            // 調用
            return exporter.getInvoker().invoke(invocation);
        }
        //Invoker這個invoker就是暴露時創建的 Invoker裏面包類似springmvcWapper
 
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章