From 7047c01968d9d12038f9a145c5688e9fdb81a7e5 Mon Sep 17 00:00:00 2001 From: Sergej Hoffmann <97111299+SevenWaysDP@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:55:14 +0200 Subject: [PATCH] BC-5661 - refactor RabbitMQ configuration (#4963) --- .../src/infra/rabbitmq/exchange/files-preview.ts | 4 ---- .../src/infra/rabbitmq/exchange/files-storage.ts | 3 --- apps/server/src/infra/rabbitmq/index.ts | 1 + apps/server/src/infra/rabbitmq/rabbitmq.config.ts | 7 +++++++ apps/server/src/infra/rabbitmq/rabbitmq.module.ts | 15 ++++++++++----- 5 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 apps/server/src/infra/rabbitmq/rabbitmq.config.ts diff --git a/apps/server/src/infra/rabbitmq/exchange/files-preview.ts b/apps/server/src/infra/rabbitmq/exchange/files-preview.ts index 0bab7491e07..61b938feecd 100644 --- a/apps/server/src/infra/rabbitmq/exchange/files-preview.ts +++ b/apps/server/src/infra/rabbitmq/exchange/files-preview.ts @@ -1,7 +1,3 @@ -import { Configuration } from '@hpi-schul-cloud/commons/lib'; - -export const FilesPreviewExchange = Configuration.get('FILES_STORAGE__EXCHANGE') as string; - export enum FilesPreviewEvents { 'GENERATE_PREVIEW' = 'generate-preview', } diff --git a/apps/server/src/infra/rabbitmq/exchange/files-storage.ts b/apps/server/src/infra/rabbitmq/exchange/files-storage.ts index 9677777b084..15a9139fec7 100644 --- a/apps/server/src/infra/rabbitmq/exchange/files-storage.ts +++ b/apps/server/src/infra/rabbitmq/exchange/files-storage.ts @@ -1,8 +1,5 @@ -import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { EntityId } from '@shared/domain/types'; -export const FilesStorageExchange = Configuration.get('FILES_STORAGE__EXCHANGE') as string; - export enum FilesStorageEvents { 'COPY_FILES_OF_PARENT' = 'copy-files-of-parent', 'LIST_FILES_OF_PARENT' = 'list-files-of-parent', diff --git a/apps/server/src/infra/rabbitmq/index.ts b/apps/server/src/infra/rabbitmq/index.ts index 99f5887b9a8..53e075c9516 100644 --- a/apps/server/src/infra/rabbitmq/index.ts +++ b/apps/server/src/infra/rabbitmq/index.ts @@ -1,5 +1,6 @@ export * from './error.mapper'; export * from './exchange'; +export * from './rabbitmq.config'; export * from './rabbitmq.module'; export * from './rpc-message'; export * from './rpc-message-producer'; diff --git a/apps/server/src/infra/rabbitmq/rabbitmq.config.ts b/apps/server/src/infra/rabbitmq/rabbitmq.config.ts new file mode 100644 index 00000000000..f5eee733deb --- /dev/null +++ b/apps/server/src/infra/rabbitmq/rabbitmq.config.ts @@ -0,0 +1,7 @@ +import { Configuration } from '@hpi-schul-cloud/commons/lib'; + +export const FilesPreviewExchange = Configuration.get('FILES_STORAGE__EXCHANGE') as string; +export const FilesStorageExchange = Configuration.get('FILES_STORAGE__EXCHANGE') as string; +export const MailSendExchange = Configuration.get('MAIL_SEND_EXCHANGE') as string; +export const AntivirusExchange = Configuration.get('ANTIVIRUS_EXCHANGE') as string; +export const RabbitMqURI = Configuration.get('RABBITMQ_URI') as string; diff --git a/apps/server/src/infra/rabbitmq/rabbitmq.module.ts b/apps/server/src/infra/rabbitmq/rabbitmq.module.ts index 946b642e779..2600e0e2136 100644 --- a/apps/server/src/infra/rabbitmq/rabbitmq.module.ts +++ b/apps/server/src/infra/rabbitmq/rabbitmq.module.ts @@ -1,7 +1,12 @@ import { AmqpConnectionManager, RabbitMQModule } from '@golevelup/nestjs-rabbitmq'; -import { Configuration } from '@hpi-schul-cloud/commons'; import { Global, Module, OnModuleDestroy } from '@nestjs/common'; -import { FilesPreviewExchange, FilesStorageExchange } from './exchange'; +import { + AntivirusExchange, + FilesPreviewExchange, + FilesStorageExchange, + MailSendExchange, + RabbitMqURI, +} from './rabbitmq.config'; /** * https://www.npmjs.com/package/@golevelup/nestjs-rabbitmq#usage @@ -17,11 +22,11 @@ const imports = [ prefetchCount: 5, exchanges: [ { - name: Configuration.get('MAIL_SEND_EXCHANGE') as string, + name: MailSendExchange, type: 'direct', }, { - name: Configuration.get('ANTIVIRUS_EXCHANGE') as string, + name: AntivirusExchange, type: 'direct', }, { @@ -33,7 +38,7 @@ const imports = [ type: 'direct', }, ], - uri: Configuration.get('RABBITMQ_URI') as string, + uri: RabbitMqURI, }), ]; @Global()