Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(repeater): preserve legacy rabbitmq flow #435

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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