【问题标题】:kafkajs - Wrong password for SASL authentication did not raise an errorkafkajs - SASL 身份验证的错误密码未引发错误
【发布时间】:2020-05-04 04:56:31
【问题描述】:

这是我使用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)
    }
}

【问题讨论】:

  • 你能显示你的相关server.properties。您是如何在代理端设置 SASL 的?

标签: security authentication apache-kafka passwords kafkajs


【解决方案1】:

如果身份验证失败,KafkaJS 将在 connect 上抛出错误。 See this test for example.

很可能您没有在代理端正确设置身份验证。 See the documentation 了解如何在代理上配置 SASL。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-12
    • 2019-12-16
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 2020-09-04
    • 2015-05-17
    • 1970-01-01
    相关资源
    最近更新 更多