JetstreamModule
Defined in: src/jetstream.module.ts:86
Root module for the NestJS JetStream transport.
-
forRoot()/forRootAsync()— registers once in AppModule. Creates shared NATS connection, codec, event bus, and optionally the consumer infrastructure. -
forFeature()— registers in feature modules. Creates a lightweight client proxy targeting a specific service.
Example
// AppModule — global setup
@Module({
imports: [
JetstreamModule.forRoot({
name: 'orders',
servers: ['nats://localhost:4222'],
}),
],
})
export class AppModule {}
// Feature module — per-service clients
@Module({
imports: [
JetstreamModule.forFeature({ name: 'users' }),
JetstreamModule.forFeature({ name: 'payments' }),
],
})
export class OrdersModule {}
Implements
OnApplicationShutdown
Constructors
Constructor
new JetstreamModule(
shutdownManager?,strategy?):JetstreamModule
Defined in: src/jetstream.module.ts:87
Parameters
shutdownManager?
ShutdownManager
strategy?
JetstreamStrategy | null
Returns
JetstreamModule
Methods
onApplicationShutdown()
onApplicationShutdown():
Promise<void>
Defined in: src/jetstream.module.ts:566
Gracefully shut down the transport on application termination.
Returns
Promise<void>
Implementation of
OnApplicationShutdown.onApplicationShutdown
forFeature()
staticforFeature(options):DynamicModule
Defined in: src/jetstream.module.ts:173
Register a lightweight client proxy for a target service.
Reuses the shared NATS connection from forRoot().
Import in each feature module that needs to communicate with a specific service.
Parameters
options
Feature options with target service name.
Returns
DynamicModule
Dynamic module with the client provider.
forRoot()
staticforRoot(options):DynamicModule
Defined in: src/jetstream.module.ts:107
Register the JetStream transport globally.
Creates a shared NATS connection, codec, event bus, and optionally the full consumer infrastructure (streams, consumers, routers).
Parameters
options
Module configuration.
Returns
DynamicModule
Dynamic module ready to be imported.
forRootAsync()
staticforRootAsync(asyncOptions):DynamicModule
Defined in: src/jetstream.module.ts:139
Register the JetStream transport globally with async configuration.
Supports useFactory, useExisting, and useClass patterns
for loading configuration from ConfigService, environment, etc.
Parameters
asyncOptions
Async configuration.
Returns
DynamicModule
Dynamic module ready to be imported.