尽管主题和生产者都存在,但无法发送 Kafka 消息

Can't send Kafka messages though topic and producer both exist

我在本地使用 TypeScript 和 KafkaJS 库,使用一个 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() 时,问题就解决了。