From 351a2e14b8f16a784c8ee654abb24f927e81f6f3 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Wed, 30 Mar 2022 23:34:17 -0500 Subject: [PATCH] Prevent request Bus instances from creating new IORedis connections --- package.json | 2 +- .../module/InjectRequestEventBusHTTPModule.ts | 2 +- src/support/bus/Bus.ts | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 0f13816..b2d66de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@extollo/lib", - "version": "0.9.17", + "version": "0.9.18", "description": "The framework library that lifts up your code.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/http/kernel/module/InjectRequestEventBusHTTPModule.ts b/src/http/kernel/module/InjectRequestEventBusHTTPModule.ts index 0e538f3..45eee30 100644 --- a/src/http/kernel/module/InjectRequestEventBusHTTPModule.ts +++ b/src/http/kernel/module/InjectRequestEventBusHTTPModule.ts @@ -19,7 +19,7 @@ export class InjectRequestEventBusHTTPModule extends HTTPKernelModule { public async apply(request: Request): Promise { const requestBus = this.container().makeNew(Bus) - await requestBus.up() + await requestBus.up(false) await requestBus.connect(this.bus) request.purge(Bus).registerProducer(Bus, () => requestBus) diff --git a/src/support/bus/Bus.ts b/src/support/bus/Bus.ts index a97c108..9b97bf9 100644 --- a/src/support/bus/Bus.ts +++ b/src/support/bus/Bus.ts @@ -188,7 +188,7 @@ export class Bus extends Unit implements EventBus< } /** Initialize this event bus. */ - async up(): Promise { + async up(createUpstreamFromConfig = true): Promise { if ( this.isUp ) { this.logging.warn('Attempted to boot more than once. Skipping.') ifDebugging('extollo.bus', () => { @@ -198,12 +198,14 @@ export class Bus extends Unit implements EventBus< } // Read the connectors from the server.bus config and set them up - const config = this.config.get('server.bus', {}) - if ( Array.isArray(config.connectors) ) { - for ( const connector of (config.connectors as BusConnectorConfig[]) ) { - this.logging.verbose(`Creating bus connection of type: ${connector.type}`) - if ( connector.type === 'redis' ) { - await this.connect(this.make(RedisBus)) + if ( createUpstreamFromConfig ) { + const config = this.config.get('server.bus', {}) + if ( Array.isArray(config.connectors) ) { + for ( const connector of (config.connectors as BusConnectorConfig[]) ) { + this.logging.verbose(`Creating bus connection of type: ${connector.type}`) + if ( connector.type === 'redis' ) { + await this.connect(this.make(RedisBus)) + } } } }