pulsar-client-1-2 PulsarClient构造函数

本文深入解析PulsarClient的构造过程,涉及EventLoopGroup、ConnectionPool、LookupService以及Producer的创建。PulsarClient通过ctor1-ctor3初始化关键组件,如MemoryLimitController和HttpClient。LookupService用于查找topic对应的broker,而ConnectionPool管理与broker的连接。Producer创建涉及topic元数据查询,确保正确分区消息。HttpClient则负责向serviceURL发送HTTP请求。
摘要由CSDN通过智能技术生成

前言

上文说到,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 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值