Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lifecycle of producers and consumers #135

Merged
merged 6 commits into from
Sep 4, 2024
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
Loading