refactor: ( payment ) use rabbitmq for webhooks event

This commit is contained in:
Abubeker Yasin
2026-06-13 20:19:23 +03:00
parent eb94d58a4e
commit c35b5089ce
17 changed files with 396 additions and 10 deletions

View File

@@ -0,0 +1,23 @@
import { registerAs } from "@nestjs/config";
/**
* RabbitMQ connection for the outbox event publisher (payment -> apps).
* `publisherTransport` selects which PaymentEventPublisher the outbox relay uses:
* "rabbitmq" -> RabbitMqPaymentEventPublisher (publish to the payment.events exchange) [DEFAULT]
* "http" -> HttpPaymentEventPublisher (POST to each app's mark-paid endpoint) [rollback]
* RabbitMQ is the default; set PUBLISHER_TRANSPORT=http explicitly to fall back to HTTP.
*/
export default registerAs("rabbitmq", () => ({
url: process.env.PAYMENT_RABBITMQ_URL ?? "amqp://localhost:5672/payment",
publisherTransport: (process.env.PUBLISHER_TRANSPORT ?? "rabbitmq").toLowerCase(),
/** Publish is failed (so the relay retries) if the broker does not confirm within this. */
publishTimeoutMs: parseInt(process.env.PAYMENT_PUBLISH_TIMEOUT_MS ?? "10000", 10),
}));
/**
* True when the outbox relay should publish to RabbitMQ rather than POST over HTTP.
* RabbitMQ is the default; only an explicit PUBLISHER_TRANSPORT=http opts out.
*/
export function isRabbitPublisher(): boolean {
return (process.env.PUBLISHER_TRANSPORT ?? "rabbitmq").toLowerCase() !== "http";
}