Skip to content

Commit

Permalink
feat(repeater): preserve legacy rabbitmq flow (#435)
Browse files Browse the repository at this point in the history
relates-to: #404
  • Loading branch information
lsndr authored Aug 17, 2023
1 parent b577a95 commit 451d6e4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
40 changes: 37 additions & 3 deletions src/Commands/RunRepeater.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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')
Expand All @@ -149,7 +161,7 @@ export class RunRepeater implements CommandModule {

return true;
})
.middleware((args: Arguments) =>
.middleware((args: Arguments) => {
container
.register<RequestExecutorOptions>(RequestExecutorOptions, {
useValue: {
Expand Down Expand Up @@ -177,6 +189,19 @@ export class RunRepeater implements CommandModule {
]
}
})
.register<RabbitMQBusOptions>(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>(
DefaultRepeaterServerOptions,
{
Expand All @@ -188,7 +213,16 @@ export class RunRepeater implements CommandModule {
}
}
)
);
.register<RepeaterLauncher>(
RepeaterLauncher,
{
useClass: args.legacy
? DefaultRepeaterLauncher
: ServerRepeaterLauncher
},
{ lifecycle: Lifecycle.Singleton }
);
});
}

// eslint-disable-next-line complexity
Expand Down
12 changes: 1 addition & 11 deletions src/Config/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -209,11 +204,6 @@ container
{ useClass: DefaultConfigReader },
{ lifecycle: Lifecycle.Singleton }
)
.register<RepeaterLauncher>(
RepeaterLauncher,
{ useClass: ServerRepeaterLauncher },
{ lifecycle: Lifecycle.Singleton }
)
.register<CliBuilder>(CliBuilder, {
useFactory: (deps) =>
new CliBuilder({
Expand Down
3 changes: 3 additions & 0 deletions src/Repeater/DefaultRepeaterLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 451d6e4

Please sign in to comment.