gpt4 book ai didi

node.js - Kafka Node - client.createTopic 失败代码 38

转载 作者:行者123 更新时间:2023-12-02 20:42:31 26 4
gpt4 key购买 nike

我在创建主题的 Node 中创建了一个小的 kafka 代码。
我总是得到没有错误的响应,但在数据内部有一个错误:

received error code 38 for topic.



我正在使用 kafka docker 连接到 kafka。图片:
wurstmeister/zookeeper

这是代码:
const kafka = require('kafka-node')
consumerOptions = {groupId: 'auditGroup'}
const topic = 'Audit-test3'
const {
Producer, Consumer, KeyedMessage, ConsumerGroup,
} = kafka
const kafkaHost = 'localhost:9092'
console.log(`kafka - URL = ${kafkaHost}`)

const clientTopic = {
topic,
partitions: 10,
replicationFactor: 3
}

const client = new kafka.KafkaClient({ kafkaHost })
const producer = new Producer(client)
const consumer = new Consumer(client, [], { autoCommit: true, ...consumerOptions })


client.once('connect', () => {
console.log('kafka - client connected')
client.createTopics([clientTopic], clientTopicCallback)
client.refreshMetadata([topic], () => console.log('kafka - client connected and refreshed metadata'))
})

const clientTopicCallback = (err, data) => {
if(err){
console.error(`kafka - error createing topic at client. ${err.message}. ${err.stack}`, err)
return
}

if(data[0].error){
console.error(`kafka - error createing topic at client. ${data[0].error}.`)
}
}

最佳答案

错误代码 38 表示复制因子无效。你有多少个卡夫卡经纪人?如果要将复制因子设置为 3,则至少需要 3 个可用的代理。

关于node.js - Kafka Node - client.createTopic 失败代码 38,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60866959/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com