diff --git a/packages/core/server/src/application.ts b/packages/core/server/src/application.ts index 5f929e87cd..da22ab1659 100644 --- a/packages/core/server/src/application.ts +++ b/packages/core/server/src/application.ts @@ -60,7 +60,7 @@ import { dataTemplate } from './middlewares/data-template'; import validateFilterParams from './middlewares/validate-filter-params'; import { Plugin } from './plugin'; import { InstallOptions, PluginManager } from './plugin-manager'; -import { PubSubManager, PubSubManagerOptions } from './pub-sub-manager'; +import { createPubSubManager, PubSubManager, PubSubManagerOptions } from './pub-sub-manager'; import { SyncManager } from './sync-manager'; import { SyncMessageManager } from './sync-message-manager'; @@ -1132,7 +1132,7 @@ export class Application exten this._cli = this.createCLI(); this._i18n = createI18n(options); this.syncManager = new SyncManager(this); - this.pubSubManager = PubSubManager.create(this, { + this.pubSubManager = createPubSubManager(this, { channelPrefix: this.name, ...options.pubSubManager, }); diff --git a/packages/core/server/src/pub-sub-manager.ts b/packages/core/server/src/pub-sub-manager.ts index 80b6f4b90e..a76e0864d2 100644 --- a/packages/core/server/src/pub-sub-manager.ts +++ b/packages/core/server/src/pub-sub-manager.ts @@ -25,23 +25,23 @@ export interface PubSubManagerSubscribeOptions { debounce?: number; } +export const createPubSubManager = (app: Application, options: PubSubManagerOptions) => { + const pubSubManager = new PubSubManager(options); + app.on('afterStart', async () => { + await pubSubManager.connect(); + }); + app.on('afterStop', async () => { + await pubSubManager.close(); + }); + return pubSubManager; +}; + export class PubSubManager { adapter: IPubSubAdapter; messageHandlers = new Map(); subscribes = new Map(); publisherId: string; - static create(app: Application, options: PubSubManagerOptions) { - const pubSubManager = new PubSubManager(options); - app.on('afterStart', async () => { - await pubSubManager.connect(); - }); - app.on('afterStop', async () => { - await pubSubManager.close(); - }); - return pubSubManager; - } - constructor(protected options: PubSubManagerOptions = {}) { this.publisherId = uid(); }