使用KafkaJS创建主题时出错

inkz8wg9  于 9个月前  发布在  Apache
关注(0)|答案(2)|浏览(92)

我使用KafkaJS来创建主题。

const kafka = new Kafka({

  connectionTimeout: 10_000,
  authenticationTimeout: 10_000,
  brokers: [`HOST_NAME:9092`],
  clientId: 'example-producer',
  ssl: {
    servername: 'HOST_NAME',
    rejectUnauthorized: false
  },
  sasl: {
    mechanism: 'plain',
    username: '*******',
    password: '******'
  }
})

const admin = kafka.admin();
await admin.connect()

const topic = 'test-topics';
const run = async () => {
  await admin.connect()
  await admin.createTopics({
    topics: [{ topic }],
    waitForLeaders: true,
  })
  await admin.createPartitions({
    topicPartitions: [{ topic: topic, count: 1}],
  })
}
run().catch(e => kafka.logger().error(`[Kafka-config] ${e.message}`, { stack: e.stack }));

字符串
获取以下错误:

message”:“[Connection] Response Topics(key:19,version:3)",“broker”:“HOST_NAME:9092”,“clientId”:“example-producer”,“error”:“Request parameters do not satisfy configured policy”,“correlationId”:3,“size”:58}

但是,当我试图列出集群中存在的主题时,我得到了成功的响应,因为主题已经存在。

v6ylcynt

v6ylcynt1#

添加topics: [{ topic **,replicationFactor: 3**}]解决了问题

eqfvzcg8

eqfvzcg82#

我必须指定replicationFactornumPartitions才能让它工作:

const result = await admin.createTopics({
  topics: [{ topic: "test1234", numPartitions: 1, replicationFactor: 3 }],
});
console.log(result);  //true

字符串

相关问题