我在本地使用KafkaJS库的TypeScript工作,使用单个kafka代理。我已经成功连接了一个生产者,验证了我的主题已经创建,并且正在生成消息:
const changeMessage = {
key: id,
value: JSON.stringify(person),
headers: {
changeType: status,
},
};
现在当我发送消息时:
try {
const sendResponse = await producer.send({
topic: topicName2,
messages: [changeMessage],
});
log.responseFragment(
{ id, topicName2 },
`Sending changed/added person ${id} to topic ${topicName2}`
);
} catch (error) {
log.error(
{ error }, `Could not send personChangedAdded ${id} to topic ${topicName2}`
);
}
这是我得到的错误:
Could not send personChange to topic topicName2
error: {
"name": "KafkaJSError",
"retriable": true
}
我未能定义log.responseFragment()
,当我将其更改为简单的log.info()
时,问题就解决了。