You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PulsarAdmin API获取主题分区数时遇URI解析错误求助

问题排查:PulsarAdmin API无法获取主题分区数

核心问题分析

报错信息显示pulsar+ssl://mypath.com:1234/admin/v2/persistent/abc/def/myplacev1/partitions无法解析为有效URI,本质原因是PulsarAdmin的serviceHttpUrl参数误用了Broker连接协议:

  • pulsar+ssl://是Pulsar客户端(PulsarClient)连接Broker的协议,而非Admin API的HTTP服务协议
  • Admin API必须使用http://或https://作为协议前缀

排查与修复步骤

  • 修正serviceUrl协议与端口:
    将serviceUrl从pulsar+ssl://mypath.com:1234替换为集群Admin服务的HTTP/HTTPS地址,例如:

    // 示例:使用HTTPS协议,默认Admin HTTPS端口为8443
    val serviceUrl = "https://mypath.com:8443"
    

    注意:1234大概率是Broker的pulsar+ssl端口(默认6651),需替换为Admin服务的实际端口(默认HTTP 8080、HTTPS 8443)。

  • 验证Admin API地址可用性:
    用curl直接测试Admin接口,确认地址可访问:

    curl --cacert /path/to/trust-cert.pem https://mypath.com:8443/admin/v2/persistent/abc/def/myplacev1/partitions
    

    若能返回JSON格式的分区元数据,说明地址配置正确。

  • 检查证书与安全配置:
    确保tlsTrustCertsFilePath指向正确的CA证书文件,allowTlsInsecureConnection的设置与集群匹配(自签名证书场景需设为true)。

  • 修正后的完整代码示例:

    val admin: PulsarAdmin =
        PulsarAdmin
            .builder()
            .authentication(authParams)
            .serviceHttpUrl("https://mypath.com:8443") // 修正为Admin HTTPS地址
            .tlsTrustCertsFilePath(tlsTrustCertsFilePath)
            .allowTlsInsecureConnection(tlsAllowInsecureConnection)
            .build()
    
    println(admin.topics().getPartitionedTopicMetadata(inputTopic))
    

内容的提问来源于stack exchange,提问作者dmonopoly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 15:12:35