@@ -24,13 +24,16 @@ import { safeJsonDeserializer } from './utils/safeJsonDeserializer.js'
2424export type KafkaConsumerDependencies = KafkaDependencies &
2525 Pick < QueueConsumerDependencies , 'transactionObservabilityManager' >
2626
27- export type KafkaConsumerOptions < TopicsConfig extends TopicConfig [ ] > = BaseKafkaOptions &
27+ export type KafkaConsumerOptions <
28+ TopicsConfig extends TopicConfig [ ] ,
29+ ExecutionContext ,
30+ > = BaseKafkaOptions &
2831 Omit <
2932 ConsumerOptions < string , object , string , string > ,
3033 'deserializers' | 'autocommit' | keyof KafkaConfig
3134 > &
3235 Omit < ConsumeOptions < string , object , string , string > , 'topics' > & {
33- handlers : KafkaHandlerRouting < TopicsConfig >
36+ handlers : KafkaHandlerRouting < TopicsConfig , ExecutionContext >
3437 }
3538
3639/*
@@ -41,24 +44,28 @@ const MAX_IN_MEMORY_RETRIES = 3
4144
4245export abstract class AbstractKafkaConsumer <
4346 TopicsConfig extends TopicConfig [ ] ,
44- > extends AbstractKafkaService < TopicsConfig , KafkaConsumerOptions < TopicsConfig > > {
47+ ExecutionContext ,
48+ > extends AbstractKafkaService < TopicsConfig , KafkaConsumerOptions < TopicsConfig , ExecutionContext > > {
4549 private readonly consumer : Consumer < string , object , string , string >
4650 private consumerStream ?: MessagesStream < string , object , string , string >
4751
4852 private readonly transactionObservabilityManager : TransactionObservabilityManager
49- private readonly handlerContainer : KafkaHandlerContainer < TopicsConfig >
53+ private readonly handlerContainer : KafkaHandlerContainer < TopicsConfig , ExecutionContext >
54+ private readonly executionContext : ExecutionContext
5055
5156 constructor (
5257 dependencies : KafkaConsumerDependencies ,
53- options : KafkaConsumerOptions < TopicsConfig > ,
58+ options : KafkaConsumerOptions < TopicsConfig , ExecutionContext > ,
59+ executionContext : ExecutionContext ,
5460 ) {
5561 super ( dependencies , options )
5662
5763 this . transactionObservabilityManager = dependencies . transactionObservabilityManager
58- this . handlerContainer = new KafkaHandlerContainer < TopicsConfig > (
64+ this . handlerContainer = new KafkaHandlerContainer < TopicsConfig , ExecutionContext > (
5965 options . handlers ,
6066 options . messageTypeField ,
6167 )
68+ this . executionContext = executionContext
6269
6370 this . consumer = new Consumer ( {
6471 ...this . options . kafka ,
@@ -169,11 +176,11 @@ export abstract class AbstractKafkaConsumer<
169176
170177 private async tryToConsume < MessageValue extends object > (
171178 message : Message < string , MessageValue , string , string > ,
172- handler : KafkaHandler < MessageValue > ,
179+ handler : KafkaHandler < MessageValue , ExecutionContext > ,
173180 requestContext : RequestContext ,
174181 ) : Promise < boolean > {
175182 try {
176- await handler ( message , requestContext )
183+ await handler ( message , this . executionContext , requestContext )
177184 return true
178185 } catch ( error ) {
179186 this . handlerError ( error , {
0 commit comments