File tree Expand file tree Collapse file tree 4 files changed +14
-7
lines changed
test/promisified/consumer Expand file tree Collapse file tree 4 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,12 @@ class Consumer {
73
73
*/
74
74
#pausedPartitions = new Set ( ) ;
75
75
76
+ /**
77
+ * Contains a list of stored topics/regexes that the user has subscribed to.
78
+ * @type {(string|RegExp)[] }
79
+ */
80
+ #storedSubscriptions = [ ] ;
81
+
76
82
/**
77
83
* @constructor
78
84
* @param {import("../../types/kafkajs").ConsumerConfig } kJSConfig
@@ -425,7 +431,8 @@ class Consumer {
425
431
}
426
432
} ) ;
427
433
428
- this . #internalClient. subscribe ( topics ) ;
434
+ this . #storedSubscriptions = subscription . replace ? topics : this . #storedSubscriptions. concat ( topics ) ;
435
+ this . #internalClient. subscribe ( this . #storedSubscriptions) ;
429
436
}
430
437
431
438
async stop ( ) {
Original file line number Diff line number Diff line change @@ -68,8 +68,8 @@ describe('Consumer', () => {
68
68
/* Send the first 2 messages to each topic. */
69
69
for ( const topic of topics ) {
70
70
await producer . send ( { topic, messages : messages . slice ( 0 , 2 ) } ) ;
71
+ await consumer . subscribe ( { topic } ) ;
71
72
}
72
- await consumer . subscribe ( { topics : topics } ) ;
73
73
74
74
let shouldPause = true ;
75
75
let pauseMessageRecvd = false ;
@@ -141,7 +141,7 @@ describe('Consumer', () => {
141
141
for ( const topic of topics ) {
142
142
await producer . send ( { topic, messages : messages . slice ( 0 , 2 ) } )
143
143
}
144
- await consumer . subscribe ( { topics } )
144
+ await consumer . subscribe ( { topics, replace : true } ) ;
145
145
146
146
let shouldPause = true
147
147
const messagesConsumed = [ ]
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ describe('Consumer', () => {
71
71
expect ( messagesConsumed . map ( m => m . message . value . toString ( ) ) ) . toEqual (
72
72
expect . arrayContaining ( [ 'drink' , 'your' , 'ovaltine' ] )
73
73
) ;
74
- } , 10000 ) ;
74
+ } ) ;
75
75
} )
76
76
77
77
describe ( 'Deprecated "topic" interface' , ( ) => {
@@ -151,7 +151,7 @@ describe('Consumer', () => {
151
151
'value-br' ,
152
152
'value-se' ,
153
153
] ) ;
154
- } , 10000 ) ;
154
+ } ) ;
155
155
} ) ;
156
156
} ) ;
157
157
} ) ;
Original file line number Diff line number Diff line change @@ -376,9 +376,9 @@ export type EachBatchHandler = (payload: EachBatchPayload) => Promise<void>
376
376
377
377
export type EachMessageHandler = ( payload : EachMessagePayload ) => Promise < void >
378
378
379
- export type ConsumerSubscribeTopic = { topic : string | RegExp ; fromBeginning ?: boolean }
379
+ export type ConsumerSubscribeTopic = { topic : string | RegExp ; fromBeginning ?: boolean , replace ?: boolean }
380
380
381
- export type ConsumerSubscribeTopics = { topics : ( string | RegExp ) [ ] ; fromBeginning ?: boolean }
381
+ export type ConsumerSubscribeTopics = { topics : ( string | RegExp ) [ ] ; fromBeginning ?: boolean , replace ?: boolean }
382
382
383
383
export type ConsumerRunConfig = {
384
384
autoCommit ?: boolean
You can’t perform that action at this time.
0 commit comments