mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import { Module } from "@nestjs/common";
|
|
import { HttpModule } from "@nestjs/axios";
|
|
import { ConfigService } from "@nestjs/config";
|
|
import { TypeOrmModule } from "@nestjs/typeorm";
|
|
import { RabbitMQModule } from "@golevelup/nestjs-rabbitmq";
|
|
import { PAYMENT_EVENTS_DLX, PAYMENT_EVENTS_EXCHANGE } from "@edr/types";
|
|
import { isRabbitPublisher } from "../../config/rabbitmq.config";
|
|
import { NotificationOutbox } from "./entities/notification-outbox.entity";
|
|
import { OutboxRelayService } from "./outbox-relay.service";
|
|
import { OutboxRepository } from "./outbox.repository";
|
|
import { HttpPaymentEventPublisher } from "./publisher/http-payment-event-publisher";
|
|
import { PAYMENT_EVENT_PUBLISHER } from "./publisher/payment-event-publisher";
|
|
import { RabbitMqPaymentEventPublisher } from "./publisher/rabbitmq-payment-event-publisher";
|
|
import { TestEventsController } from "./test-events.controller";
|
|
|
|
// Dev-only harness to publish a synthetic payment event straight to the broker.
|
|
// Never registered in production, so the endpoint cannot exist there.
|
|
const testControllers =
|
|
process.env.NODE_ENV !== "production" ? [TestEventsController] : [];
|
|
|
|
const rabbitImports = isRabbitPublisher()
|
|
? [
|
|
RabbitMQModule.forRootAsync({
|
|
inject: [ConfigService],
|
|
useFactory: (config: ConfigService) => ({
|
|
uri: config.get<string>("rabbitmq.url") as string,
|
|
exchanges: [
|
|
{
|
|
name: PAYMENT_EVENTS_EXCHANGE,
|
|
type: "topic",
|
|
options: { durable: true },
|
|
},
|
|
{
|
|
name: PAYMENT_EVENTS_DLX,
|
|
type: "topic",
|
|
options: { durable: true },
|
|
},
|
|
],
|
|
connectionInitOptions: { wait: false },
|
|
}),
|
|
}),
|
|
]
|
|
: [];
|
|
|
|
@Module({
|
|
imports: [
|
|
TypeOrmModule.forFeature([NotificationOutbox]),
|
|
HttpModule,
|
|
...rabbitImports,
|
|
],
|
|
controllers: testControllers,
|
|
providers: [
|
|
OutboxRepository,
|
|
OutboxRelayService,
|
|
{
|
|
provide: PAYMENT_EVENT_PUBLISHER,
|
|
useClass: isRabbitPublisher()
|
|
? RabbitMqPaymentEventPublisher
|
|
: HttpPaymentEventPublisher,
|
|
},
|
|
],
|
|
exports: [OutboxRepository],
|
|
})
|
|
export class OutboxModule {}
|