前言
上文说到,PulsarClient通过链式调用构建,而在build()
中调用了new PulsarClientImpl(conf)
,而Producer 本文通过解析构造函数,了解其主要结构。
// 创建PulsarClient
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar://localhost:6650")
.build();
@Override
public PulsarClient build() throws PulsarClientException {
// 1. 参数检验
...
// 2. 构造PulsarClient
PulsarClient client = new PulsarClientImpl(conf);
if (conf.getServiceUrlProvider() != null) {
conf.getServiceUrlProvider().initialize(client);
}
return client;
}
PulsarClient构造函数
构造函数依次调用了下文的ctor1、ctor2、ctor3(见注释)。其中ctor1创建了EventLoopGroup, ctor2创建了ConnectionPool,ctor3创建的组件较多,内容省略。
// ctor1
public PulsarClientImpl(ClientConfigurationData conf) throws PulsarClientException