MCPcopy
hub / github.com/nestjs/nest / connect

Method connect

packages/microservices/client/client-rmq.ts:109–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

107 }
108
109 public connect(): Promise<any> {
110 if (this.client) {
111 return this.connectionPromise;
112 }
113 this.client = this.createClient();
114
115 this.registerErrorListener(this.client);
116 this.registerDisconnectListener(this.client);
117 this.registerConnectListener(this.client);
118 this.registerBlockedListener(this.client);
119 this.registerUnblockedListener(this.client);
120 this.pendingEventListeners.forEach(({ event, callback }) =>
121 this.client!.on(event, callback),
122 );
123 this.pendingEventListeners = [];
124
125 this.responseEmitter = new EventEmitter();
126 this.responseEmitter.setMaxListeners(0);
127
128 const connect$ = this.connect$(this.client);
129 const withDisconnect$ = this.mergeDisconnectEvent(
130 this.client,
131 connect$,
132 ).pipe(switchMap(() => this.createChannel()));
133
134 const withReconnect$ = fromEvent(this.client, RmqEventsMap.CONNECT).pipe(
135 skip(1),
136 );
137 const source$ = merge(withDisconnect$, withReconnect$);
138
139 this.connection$ = new ReplaySubject(1);
140 source$.subscribe(this.connection$);
141 this.connectionPromise = this.convertConnectionToPromise();
142
143 return this.connectionPromise;
144 }
145
146 public createChannel(): Promise<void> {
147 return new Promise(resolve => {

Callers 1

createClientMethod · 0.45

Calls 12

createClientMethod · 0.95
registerErrorListenerMethod · 0.95
mergeDisconnectEventMethod · 0.95
createChannelMethod · 0.95
subscribeMethod · 0.80
onMethod · 0.65
pipeMethod · 0.45

Tested by

no test coverage detected