2

I'm working in TypeScript with the KafkaJS library locally, with a single kafka broker. I've connected a producer successfully, have verified that my topic was created, and am generating messages with:


  const changeMessage = {
    key: id,
    value: JSON.stringify(person),
    headers: {
      changeType: status,
    },
  };

Now when I go to send the message:


  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}`
    );
  }

Here's the error that I get back:

Could not send personChange to topic topicName2
    error: {
      "name": "KafkaJSError",
      "retriable": true
    }
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
mojones101
  • 161
  • 1
  • 2
  • 12
  • Are there no more details in the error you can get other than your custom message (which doesn't match the code)? Do the broker logs show anything useful? – OneCricketeer Aug 17 '21 at 16:39
  • The error does not match that piece of code. i.e. `personChangedAdded` shows in the error handler with an id, but the error show something entirely different. – Webber Aug 17 '21 at 16:45
  • I can manually send messages using the CLI and a listener can pick them up, so it's definitely something I'm doing wrong with KafkaJS – mojones101 Aug 17 '21 at 17:32
  • 1
    @OneCricketeer From inside the broker in a listener, I'm getting Received unknown topic or partition error in fetch for partition topicName2-0 (org.apache.kafka.clients.consumer.internals.Fetcher) and from the logs it's [2021-08-17 16:02:15,753] TRACE [Controller id=1 epoch=1] Received response StopReplicaResponseData(errorCode=0, partitionErrors=[StopReplicaPartitionError(topicName='IndividualEvents', partitionIndex=0, errorCode=0), StopReplicaPartition – mojones101 Aug 17 '21 at 18:01
  • 1
    Logs with `topicName='IndividualEvents'` are unrelated to your code unless that is actually your topic name. Please show where you set the value of `topicName2` – OneCricketeer Aug 17 '21 at 18:38
  • 1
    Thanks @OneCricketeer, it turns out the problem was the `log.responseFragment` bit, and when we corrected it to `log.info` it worked just fine. – mojones101 Aug 17 '21 at 18:48

1 Answers1

0

I had failed to define log.responseFragment(), and when I changed it to a simple log.info() the problem was resolved.

mojones101
  • 161
  • 1
  • 2
  • 12