Closed andres-halls closed 3 years ago
Hi @andres-liiver ,
We could look to add an option. What would be the benefit vs the current implementation now? In most cases you would want Kafka to close and the service to stop if Kafka is unreachable?
In my case, I need the Nest application to start no matter what. Kafka being down cannot prevent it from starting.
It seems the real issue is the promise rejection not being caught in https://github.com/rob3000/nestjs-kafka/blob/ee85744b3a5ed890a1a3b1d94b160011525efe8b/src/kafka.service.ts#L77
Wrapping everything in a try/catch in the connect
function fixes the issue of Nest not starting. However, after some time, another UnhandledPromiseRejectionWarning: KafkaJSNonRetriableError
is still thrown, haven't found the source of that yet.
I think adding an option to not automatically connect producer and admin still makes sense though.
Hi @andres-liiver apologies for the delay. I've just added a flag that you can can set in your config to disable the consumer and admin from auto connecting: https://github.com/rob3000/nestjs-kafka/blob/master/src/kafka.service.ts#L80-L82
Deployed in 1.4.0
Hi, currently producer and admin are automatically connected in
onModuleInit
. https://github.com/rob3000/nestjs-kafka/blob/ee85744b3a5ed890a1a3b1d94b160011525efe8b/src/kafka.service.ts#L78This causes a problem however when Kafka is unreachable. After the configured number of retries, KafkaJS will throw
KafkaJSNumberOfRetriesExceeded
which is not caught and Nest will not start. Increasing retries does not help because Nest is waiting for the module to be initialized which will never happen until the producer connects successfully.From the KafkaJS documentation:
I propose adding an option to not connect the producer and admin in
onModuleInit
, instead make it possible for users to connect manually.