-
-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does this support KRaft mode? #1563
Comments
+1 to the question of whether KafkaJS supports KRaft mode without zookeeper. |
We've just encountered the same issue; KafkaJS refuses to connect. Looking at the Kafka logs I can see:
Which looks like the topics are created nicely and without issue |
I have a way of reproducing the error in more detail. I followed https://www.npmjs.com/package/kafkajs for setup, and the proposed code there works as intended
Note that the code in question produces first, and then consumes the produced message. Producing a message to a topic by default auto-creates said topic, which is why this works. To get the problem as noted in this issue the code is tweaked a bit:
The tweaked code consumes first, and then later produces. This is the behavior of e.g. NestJS where on application startup it will subscribe to all topics that are annotated and only later will it produce any message for said topics. Now to the error itself: It seems the newer version of Kafka (I'm using 3.4.0, through the Docker image In short: Kafka seems to reject the subscription request at the time, and expects the client to retry until THE topic in question is created. This may be aligned with https://cwiki.apache.org/confluence/display/KAFKA/KIP-487%3A+Client-side+Automatic+Topic+Creation+on+Producer which seems to argue that the auto-creation of topics when e.g. subscribing should not be used anymore. Back to KafkaJS: Upon receiving this error, KafkaJs bubbles it up with e.g. stacktrace:
What especially stings about this is that Kafka actually creates the topic in the background after throwing the error, so if you re-run your app it'll find the topic on the second try. Basically: KafkaJS should retry on this error, rather than throw it and it'd most likely succeed after a few tries |
And I think this would be the fix: |
I can confirm it works with Kafka 3.4 and KRaft. If you get To verify this:
|
Does this support KRaft mode without zookeeper? Just configured kafka to use controller.quorum etc and kafkajs seems to crash on after awhile:
However connecting + creating topics on startup seemed to work fine.
The text was updated successfully, but these errors were encountered: