繁体   English   中英

kafkajs - SASL 身份验证的错误密码未引发错误

[英]kafkajs - Wrong password for SASL authentication did not raise an error

这是我使用kafkajs的制作人。 当我在options.username中提供不正确的用户名时,我会看到消息Connected 如何使用kafkajs处理连接错误?

const { Kafka, logLevel } = require('kafkajs')

async function kafkaProducer(options) {
    const kafka = new Kafka({
        brokers: [options.bootstrapServer],
        clientId: options.clientId,
        ssl: {
            rejectUnauthorized: false,
            ca: [fs.readFileSync(options.caCertPath, 'utf-8')]
        },
        sasl: {
            mechanism: options.saslMechanism, // PLAIN
            username: options.username,
            password: options.password
        },
        requestTimeout: 2000,
        retry: {
            retries: 1
        },
        logLevel: logLevel.ERROR
    })
    //
    const producer = kafka.producer()
    try {
        await producer.connect()
        console.log('Connected')
    } catch(e) {
        throw new Error(e)
    }
}

如果身份验证失败,KafkaJS 将在connect时抛出错误。 例如,请参阅此测试

您很可能没有在代理端正确设置身份验证。 有关如何在代理上配置 SASL 的信息, 请参阅文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM