You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
confluent-kafka-javascript version [e.g. 2.3.3]: 1.0.0
Overview
To connect to Kafka, the class Kafka from ('@confluentinc/kafka-javascript').KafkaJS is used to manage connections and create Producers and Consumers. However, incorrect initialization methods are presented in the README and some example codes, causing errors.
Problematic Code
Extracted and slightly modified from the README and Confluent Kafka Node.js Client examples
import{KafkaJS}from"@confluentinc/kafka-javascript";const{Kafka}=KafkaJS;asyncfunctionproduce(config?: ProducerConstructorConfig): Promise<void>{// create a new producer instanceconstproducer=newKafka().producer(config);}asyncfunctionconsume(config: ConsumerConstructorConfig){constconsumer=newKafka().consumer(config);}
Error Message
TS2554: Expected 1 arguments, but got 0
kafkajs.d.ts(97, 15): An argument for config was not provided.
The class Kafka requires CommonConstructorConfig as a mandatory argument in its constructor. However, the examples
omit this argument, leading to errors.
Cause Analysis
CommonConstructorConfig is a mandatory parameter that defines the detailed connection settings for the Kafka cluster. While omitting this argument does not cause issues in JavaScript, it results in a type error in TypeScript.
Proposed Solutions
Make CommonConstructorConfig Optional in class Kafka
Pros: Ensures compatibility with the existing example code and prevents type errors.
Cons: It may make it difficult to validate the configuration at the higher code level. Additionally, this pattern is not adopted by libraries like KafkaJS or node-rdkafka.
Modify the Example Code to Use new Kafka({})
Pros: The problem can be resolved by updating the examples without changing the codebase.
Cons: May not be backward-compatible with existing users. Additionally, it is necessary to verify if this
approach aligns with the philosophy of the library.
Additional Questions
The confluent-kafka-javascript library appears to be designed based on node-rdkafka and KafkaJS. Is it a long-term goal to migrate all functionalities of KafkaJS into this library?
The text was updated successfully, but these errors were encountered:
Thanks for filing this! I'll probably make CommonConstructorConfig optional as we are okay with someone providing the entire config in the producer({...}) call.
Regarding the other question, we have migrated most of what we targeted to migrate from KafkaJS. Depending on user feedback, we might consider some API additions or changes, but right now, this is pretty much it in terms of the migration.
A few exceptions are the AdminAPI (we plan to add more of them), and certain configuration values (like the size of the batch in the eachBatch callback).
Besides this, we won't migrate any future additions to the KafkaJS library (or node-rdkafka for that matter), and there are certain things we've chosen not to migrate (for example, the .on events). A more complete list is here: MIGRATION.md.
Thanks for filing this! I'll probably make CommonConstructorConfig optional as we are okay with someone providing the entire config in the producer({...}) call.
I think making CommonConstructorConfig optional to allow flexibility with configurations for librdkafka or KafkaJS is an excellent direction.
However, if both Kafka and Producer configurations are defined as optional, it might cause some confusion for developers, as it becomes unclear which settings are essential.
Would it be possible to mitigate this confusion by explicitly defining the minimum required fields or providing default values in the examples?
Besides this, we won't migrate any future additions to the KafkaJS library (or node-rdkafka for that matter), and there are certain things we've chosen not to migrate (for example, the .on events). A more complete list is here: MIGRATION.md.
I am currently developing an application using Nest.js and KafkaJS. Part of this involves handling lifecycle events with kafka.on() through the EventEmitter to process library-level events.
It’s a bit unfortunate to hear that this feature won’t be supported in the migration.
Could you share the reasoning behind excluding this feature from the migration plan? Understanding the background would help us find better alternatives to adapt our application. 😊
Environment Information
Overview
To connect to Kafka, the
class Kafka
from('@confluentinc/kafka-javascript').KafkaJS
is used to manage connections and create Producers and Consumers. However, incorrect initialization methods are presented in the README and some example codes, causing errors.Problematic Code
Extracted and slightly modified from the README and Confluent Kafka Node.js Client examples
Error Message
The
class Kafka
requiresCommonConstructorConfig
as a mandatory argument in its constructor. However, the examplesomit this argument, leading to errors.
Cause Analysis
CommonConstructorConfig
is a mandatory parameter that defines the detailed connection settings for the Kafka cluster. While omitting this argument does not cause issues in JavaScript, it results in a type error in TypeScript.Proposed Solutions
CommonConstructorConfig
Optional inclass Kafka
new Kafka({})
approach aligns with the philosophy of the library.
Additional Questions
The
confluent-kafka-javascript
library appears to be designed based onnode-rdkafka
andKafkaJS
. Is it a long-term goal to migrate all functionalities of KafkaJS into this library?The text was updated successfully, but these errors were encountered: