feat(api): add shared infrastructure
This commit is contained in:
1 parent
f24674b12c
commit
2e311d9cbf
10 files changed
+1088
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import fs from 'fs/promises';
|
||||
import { connect } from 'nats';
|
||||
import type { NatsConnection } from 'nats';
|
||||
import { SecretModule } from '../secret/secret.module';
|
||||
import { SecretService } from '../secret/secret.service';
|
||||
import { NATS_CLIENT } from './nats.constants';
|
||||
import { NatsService } from './nats.service';
|
||||
|
||||
@Module({
|
||||
imports: [SecretModule],
|
||||
providers: [
|
||||
{
|
||||
provide: NATS_CLIENT,
|
||||
inject: [SecretService],
|
||||
useFactory: async (
|
||||
secretService: SecretService,
|
||||
): Promise<NatsConnection> => {
|
||||
await secretService.ready();
|
||||
|
||||
const [endpoint, user, password, serviceName] = await Promise.all([
|
||||
secretService.get<string>('NATS_ENDPOINT'),
|
||||
secretService.get<string>('NATS_USER'),
|
||||
secretService.get<string>('NATS_PASS'),
|
||||
secretService.get<string>('SERVICE_NAME'),
|
||||
]);
|
||||
|
||||
return connect({
|
||||
name: serviceName,
|
||||
servers: [endpoint],
|
||||
maxReconnectAttempts: -1,
|
||||
reconnectTimeWait: 500,
|
||||
reconnect: true,
|
||||
pingInterval: 20000,
|
||||
timeout: 5000,
|
||||
user,
|
||||
pass: password,
|
||||
});
|
||||
},
|
||||
},
|
||||
NatsService,
|
||||
],
|
||||
exports: [NatsService, NATS_CLIENT],
|
||||
})
|
||||
export class NatsModule {}
|
||||
Reference in new issue
Block a user