Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

不使用证书的情况下调用ssl的url,服务无法连接

未关闭
#382 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, node.js

调研方向

先从 Node 客户端构造函数及其 tlsAllowInsecureConnection 和 tlsValidateHostname 选项开始,然后在启用客户端日志记录的情况下,针对 pulsar+ssl 服务 URL 重现提供的订阅示例。将连接失败和分区元数据失败与 Java 的行为进行比较;当禁用证书验证后,Node 客户端能够连接并创建消费者而不出现 ConnectError 时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

以下是node代码,在java中是可以通过```
PulsarClient client = PulsarClient.builder().serviceUrl(brokerServerUrl).allowTlsInsecureConnection(true)
.authentication(new IoTAuthentication(iotAccessId, iotSecretKey)).build();
Consumer consumer = client.newConsumer(Schema.STRING).topic(String.format("%s/iot/event", iotAccessId))
.subscriptionName(subscriptionName).subscriptionType(SubscriptionType.Failover)
.autoUpdatePartitions(Boolean.FALSE).subscribe();

这种方式来跳过ssl证书的,在下面node中我也加入了tlsAllowInsecureConnection: true,
            tlsValidateHostname: false,这两个参数但是无法连接到服务



`const Pulsar = require('pulsar-client');
const crypto = require('crypto');
const iotAccessId = "yGmZyJnpqPPIGwzj1564";
const iotSecretKey="b9fab8817fa64f4ab6424d6a7035d2e7";
const brokerSSLServerUrl = "pulsar+ssl://iot-north-mq.heclouds.com:6651/";
const iotSubscriptionName="yGmZyJnpqPPIGwzj1564-sub";

const token = JSON.stringify({
    tenant: iotAccessId,
    password: sha256(iotAccessId + sha256(iotSecretKey)).substring(4, 20)
});

(async () => {
    try {
        console.log("token:", token);
        // Create a client
        let authenticationToken = new Pulsar.AuthenticationToken({
            token: token
        });

        Pulsar.Client.setLogHandler((level, file, line, message) => {
            console.log('[%s][%s:%d] %s', Pulsar.LogLevel.toString(level), file, line, message);
        });

        const client = new Pulsar.Client({
            serviceUrl: brokerSSLServerUrl,
            authentication: authenticationToken,
            tlsAllowInsecureConnection: true,
            tlsValidateHostname: false,
        });


        console.log("client:", client);

        // Create a consumer
        const consumer = await client.subscribe({
            topic: `${iotAccessId}/iot/event`,
            // topic: 'persistent://yGmZyJnpqPPIGwzj1564/iot/event-partition-0',
            subscription: iotSubscriptionName,
            subscriptionType: 'Failover'
        });

        console.log("consumer:", consumer);

        // Receive the message
        const msg = await consumer.receive();
        console.log(msg.getData().toString());
        consumer.acknowledge(msg);

        await consumer.close();
        await client.close();
    } catch (error) {
        console.error("An error occurred:", error.message);
        console.error(error.stack);
    }
})();

function sha256(data) {
    return crypto.createHash('sha256').update(data, 'utf8').digest('hex');
}`


最下面是报错信息```
[INFO][Client:86] Subscribing on Topic :yGmZyJnpqPPIGwzj1564/iot/event
[INFO][ClientConnection:187] [<none> -> pulsar+ssl://iot-north-mq.heclouds.com:6651] Create ClientConnection, timeout=10000
[INFO][ConnectionPool:124] Created connection for pulsar+ssl://iot-north-mq.heclouds.com:6651-pulsar+ssl://iot-north-mq.heclouds.com:6651-0
[INFO][ClientConnection:403] [10.10.80.213:63773 -> 218.201.45.7:6651] Connected to broker
[ERROR][ClientConnection:1318] [10.10.80.213:63773 -> 218.201.45.7:6651] Connection closed with ConnectError (refCnt: 2)
[INFO][ConnectionPool:141] Remove connection for pulsar+ssl://iot-north-mq.heclouds.com:6651-pulsar+ssl://iot-north-mq.heclouds.com:6651-0
[ERROR][ClientImpl:507] Error Checking/Getting Partition Metadata while Subscribing on persistent://yGmZyJnpqPPIGwzj1564/iot/event -- ConnectError
[INFO][ClientConnection:275] [10.10.80.213:63773 -> 218.201.45.7:6651] Destroyed connection to pulsar+ssl://iot-north-mq.heclouds.com:6651-0
An error occurred: Failed to create consumer: ConnectError
Error: Failed to create consumer: ConnectError
主要语言
C++
星标
164
派生
99
平均合并
5 天 18 小时
30 天内合并 PR
2

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/pulsar-client-node 的其他 Issue

查看 apache/pulsar-client-node 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。