From 451d6e4841d838db65b5a9c7ae60aea282d71572 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 17 Aug 2023 10:51:19 +0400 Subject: [PATCH] feat(repeater): preserve legacy rabbitmq flow (#435) relates-to: #404 --- src/Commands/RunRepeater.ts | 40 +++++++++++++++++++++++-- src/Config/container.ts | 12 +------- src/Repeater/DefaultRepeaterLauncher.ts | 3 ++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/Commands/RunRepeater.ts b/src/Commands/RunRepeater.ts index 85e45d7b..739c1064 100644 --- a/src/Commands/RunRepeater.ts +++ b/src/Commands/RunRepeater.ts @@ -1,8 +1,15 @@ import { Cert, RequestExecutorOptions } from '../RequestExecutor'; import { Helpers, logger } from '../Utils'; import { container } from '../Config'; -import { DefaultRepeaterServerOptions, RepeaterLauncher } from '../Repeater'; +import { RabbitMQBusOptions } from '../Bus'; +import { + DefaultRepeaterLauncher, + DefaultRepeaterServerOptions, + RepeaterLauncher, + ServerRepeaterLauncher +} from '../Repeater'; import { Arguments, Argv, CommandModule } from 'yargs'; +import { Lifecycle } from 'tsyringe'; import { normalize } from 'path'; export class RunRepeater implements CommandModule { @@ -124,6 +131,11 @@ export class RunRepeater implements CommandModule { alias: ['rm', 'remove'], describe: 'Stop and remove repeater daemon' }) + .option('legacy', { + boolean: true, + describe: + 'Enable legacy mode, utilizing the RabbitMQ connection for communication.' + }) .conflicts('remove-daemon', 'daemon') .conflicts('experimental-connection-reuse', 'proxy') .conflicts('experimental-connection-reuse', 'proxy-external') @@ -149,7 +161,7 @@ export class RunRepeater implements CommandModule { return true; }) - .middleware((args: Arguments) => + .middleware((args: Arguments) => { container .register(RequestExecutorOptions, { useValue: { @@ -177,6 +189,19 @@ export class RunRepeater implements CommandModule { ] } }) + .register(RabbitMQBusOptions, { + useValue: { + exchange: 'EventBus', + clientQueue: `agent:${args.id as string}`, + connectTimeout: 10000, + url: args.bus as string, + proxyUrl: (args.proxyExternal ?? args.proxy) as string, + credentials: { + username: 'bot', + password: args.token as string + } + } + }) .register( DefaultRepeaterServerOptions, { @@ -188,7 +213,16 @@ export class RunRepeater implements CommandModule { } } ) - ); + .register( + RepeaterLauncher, + { + useClass: args.legacy + ? DefaultRepeaterLauncher + : ServerRepeaterLauncher + }, + { lifecycle: Lifecycle.Singleton } + ); + }); } // eslint-disable-next-line complexity diff --git a/src/Config/container.ts b/src/Config/container.ts index dd188ec3..48f6a683 100644 --- a/src/Config/container.ts +++ b/src/Config/container.ts @@ -50,12 +50,7 @@ import { ConfigReader } from './ConfigReader'; import { DefaultConfigReader } from './DefaultConfigReader'; import { CliInfo } from './CliInfo'; import { CliBuilder } from './CliBuilder'; -import { - ServerRepeaterLauncher, - RepeaterLauncher, - RepeaterServer, - DefaultRepeaterServer -} from '../Repeater'; +import { RepeaterServer, DefaultRepeaterServer } from '../Repeater'; import { container, Lifecycle } from 'tsyringe'; container @@ -209,11 +204,6 @@ container { useClass: DefaultConfigReader }, { lifecycle: Lifecycle.Singleton } ) - .register( - RepeaterLauncher, - { useClass: ServerRepeaterLauncher }, - { lifecycle: Lifecycle.Singleton } - ) .register(CliBuilder, { useFactory: (deps) => new CliBuilder({ diff --git a/src/Repeater/DefaultRepeaterLauncher.ts b/src/Repeater/DefaultRepeaterLauncher.ts index 64318663..89505429 100644 --- a/src/Repeater/DefaultRepeaterLauncher.ts +++ b/src/Repeater/DefaultRepeaterLauncher.ts @@ -127,6 +127,9 @@ export class DefaultRepeaterLauncher implements RepeaterLauncher { } logger.log('Starting the Repeater (%s)...', this.info.version); + logger.warn( + 'WARNING: You are using the legacy flow. Consider using the new repeater that utilizes standard ports.' + ); this.repeaterId = repeaterId;