Skip to content

Commit

Permalink
fix: use onApplicationShutdown to disconnect kafka producers
Browse files Browse the repository at this point in the history
  • Loading branch information
vglebovich-lmru committed Sep 2, 2024
1 parent cd7bdea commit 19b393a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/producer/kafkaCoreProducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
import {
Inject,
Injectable,
OnModuleDestroy,
OnApplicationShutdown,
OnModuleInit,
} from "@nestjs/common";
import { Producer } from "kafkajs";

import { ProducersMapToken } from "../consts";

@Injectable()
export class KafkaCoreProducer implements OnModuleInit, OnModuleDestroy {
export class KafkaCoreProducer implements OnModuleInit, OnApplicationShutdown {
public constructor(
@Inject(ProducersMapToken)
private readonly producersMap: Map<string, Producer>,
) {}

public async onModuleDestroy(): Promise<void> {
public async onApplicationShutdown(): Promise<void> {
await Promise.all(
[...this.producersMap.values()].map((x) => x.disconnect()),
);
Expand Down

0 comments on commit 19b393a

Please sign in to comment.