Skip to content

Commit fa6f3e4

Browse files
feat: channel destroy hook
1 parent 99015c4 commit fa6f3e4

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nestjstools/messaging",
3-
"version": "2.20.3",
3+
"version": "2.21.0",
44
"description": "Simplifies asynchronous and synchronous message handling with support for buses, handlers, channels, and consumers. Build scalable, decoupled applications with ease and reliability.",
55
"author": "Sebastian Iwanczyszyn",
66
"license": "MIT",

src/channel/channel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ import { ChannelConfig } from '../config';
22

33
export class Channel<T extends ChannelConfig> {
44
constructor(public readonly config: T) {}
5+
6+
async onChannelDestroy(): Promise<void> {};
57
}

src/messaging.module.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
FactoryProvider,
44
Logger as NestCommonLogger,
55
Module,
6-
OnApplicationBootstrap,
6+
OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy,
77
Provider,
88
} from '@nestjs/common';
99
import {
@@ -44,7 +44,7 @@ import { ExceptionListenerRegistry } from './exception-listener/exception-listen
4444
import { ExceptionListenerHandler } from './exception-listener/exception-listener-handler';
4545

4646
@Module({})
47-
export class MessagingModule implements OnApplicationBootstrap {
47+
export class MessagingModule implements OnApplicationBootstrap, OnModuleDestroy {
4848
static forRoot(options: MessagingModuleOptions): DynamicModule {
4949
const channels = options.channels ?? [];
5050

@@ -238,4 +238,12 @@ export class MessagingModule implements OnApplicationBootstrap {
238238
const consumer = this.moduleRef.get(DistributedConsumer);
239239
consumer.run();
240240
}
241+
242+
async onModuleDestroy(): Promise<any> {
243+
const channels: Channel<ChannelConfig>[] = this.moduleRef.get(Service.CHANNELS);
244+
245+
for (const channel of channels) {
246+
await channel.onChannelDestroy();
247+
}
248+
}
241249
}

0 commit comments

Comments
 (0)