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
Copy file name to clipboardExpand all lines: MIGRATION.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,7 +139,6 @@
139
139
140
140
#### Semantic and Per-Method Changes
141
141
142
-
*`sendBatch` is not supported (YET). However, the actual batching semantics are handled by librdkafka.
143
142
* Changes to `send`:
144
143
*`acks`, `compression` and `timeout` are not set on a per-send basis. Rather, they must be configured in the configuration.
145
144
Before:
@@ -178,6 +177,7 @@
178
177
```
179
178
180
179
*Error-handling for a failed `send` is stricter. While sending multiple messages, even if one of the messages fails, the method throws an error.
180
+
*`sendBatch` is supported. However, the actual batching semantics are handled by librdkafka, and it just acts as a wrapper around `send` (See `send`for changes).
181
181
182
182
### Consumer
183
183
@@ -219,7 +219,10 @@
219
219
#### Semantic and Per-Method Changes
220
220
221
221
222
-
* While passing a list of topics to `subscribe`, the `fromBeginning` property is not supported. Instead, the property `auto.offset.reset` needs to be used.
222
+
* Changes to subscribe:
223
+
* Regex flags are ignored while passing a topic subscription (like 'i' or 'g').
224
+
* Subscribe must be called after `connect`.
225
+
* While passing a list of topics to `subscribe`, the `fromBeginning` property is not supported. Instead, the property `auto.offset.reset` needs to be used.
thrownewerror.KafkaJSError('Either topics or topic must be specified.',{code: error.ErrorCodes.ERR__INVALID_ARG});
360
+
}
361
+
362
+
lettopics=[];
363
+
if(subscription.topic){
364
+
topics.push(subscription.topic);
365
+
}elseif(Array.isArray(subscription.topics)){
366
+
topics=subscription.topics;
367
+
}else{
368
+
thrownewerror.KafkaJSError('topics must be an object of the type ConsumerSubscribeTopics.',{code: error.ErrorCodes.ERR__INVALID_ARG});
369
+
}
370
+
371
+
topics=topics.map(topic=>{
372
+
if(typeoftopic==='string'){
373
+
returntopic;
374
+
}elseif(topicinstanceofRegExp){
375
+
// Flags are not supported, and librdkafka only considers a regex match if the first character of the regex is ^.
376
+
constregexSource=topic.source;
377
+
if(regexSource.charAt(0)!=='^')
378
+
return'^'+regexSource;
379
+
else
380
+
returnregexSource;
381
+
}else{
382
+
thrownewerror.KafkaJSError('Invalid topic '+topic+' ('+typeoftopic+'), the topic name has to be a String or a RegExp',{code: error.ErrorCodes.ERR__INVALID_ARG});
383
+
}
384
+
});
385
+
386
+
this.#internalClient.subscribe(topics);
355
387
}
356
388
357
389
asyncstop(){
@@ -541,10 +573,18 @@ class Consumer {
541
573
* @returns {Promise<void>} a promise that resolves when the consumer has disconnected.
542
574
*/
543
575
asyncdisconnect(){
544
-
if(this.#state ===ConsumerState.INIT){
545
-
thrownewerror.KafkaJSError('Disconnect can only be called once consumer is connected.',{code: error.ErrorCodes.ERR__STATE});
576
+
/* Not yet connected - no error. */
577
+
if(this.#state ==ConsumerState.INIT){
578
+
return;
546
579
}
547
580
581
+
/* TODO: We should handle a case where we are connecting, we should
582
+
* await the connection and then schedule a disconnect. */
* @param {import('../../types/kafkajs').ProducerBatch} sendOptions - The record to send. The keys `acks`, `timeout`, and `compression` are not used, and should not be set, rather, they should be set in the global config.
493
+
* @returns {Promise<import("../../types/kafkajs").RecordMetadata[]>} Resolves with the record metadata for the messages.
494
+
*/
495
+
asyncsendBatch(sendOptions){
496
+
if(this.#state !==ProducerState.CONNECTED){
497
+
thrownewerror.KafkaJSError("Cannot send without awaiting connect()",{code: error.ErrorCodes.ERR__STATE});
0 commit comments