1. 程式人生 > >dubbo的lazyconnection啥意思?

dubbo的lazyconnection啥意思?

tin quest and change ret 怎麽 creat try exchange

ExchangeClient主要有兩種實現:
HeaderExchangeClient和LazyConnectExchangeClient,前者是正常使用的

對於後者如果我們在url指定使用的話,那麽refer一個service的時候,不會建立server的transport層面的connect,而是在request發送請求的時候才建立connect

怎麽在refer的時候跳過初始化connect的,在initclient方法中:

ExchangeClient client;
try {
// connection should be lazy
if (url.getParameter(Constants.LAZY_CONNECT_KEY, false)) {
client = new LazyConnectExchangeClient(url, requestHandler);
} else {
client = Exchangers.connect(url, requestHandler);
}
} catch (RemotingException e) {
throw new RpcException("Fail to create remoting client for service(" + url + "): " + e.getMessage(), e);
}
return client;


用一個lazyclient返回給消費者,等到消費者調用request的時候,在lazyclient的request方法實現:

public ResponseFuture request(Object request) throws RemotingException {
warning(request);
initClient();
return client.request(request);
}

這個時候初始化真正的client再去調用request

dubbo的lazyconnection啥意思?