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

Method handleMessage

packages/microservices/server/server-mqtt.ts:129–167  ·  view source on GitHub ↗
(
    channel: string,
    buffer: Buffer,
    pub: MqttClient,
    originalPacket?: Record<string, any>,
  )

Source from the content-addressed store, hash-verified

127 }
128
129 public async handleMessage(
130 channel: string,
131 buffer: Buffer,
132 pub: MqttClient,
133 originalPacket?: Record<string, any>,
134 ): Promise<any> {
135 const rawPacket = this.parseMessage(buffer.toString());
136 const packet = await this.deserializer.deserialize(rawPacket, { channel });
137 const mqttContext = new MqttContext([channel, originalPacket!]);
138 if (isUndefined((packet as IncomingRequest).id)) {
139 return this.handleEvent(channel, packet, mqttContext);
140 }
141 const publish = this.getPublisher(
142 pub,
143 mqttContext,
144 (packet as IncomingRequest).id,
145 );
146 const handler = this.getHandlerByPattern(channel);
147
148 if (!handler) {
149 const status = 'error';
150 const noHandlerPacket = {
151 id: (packet as IncomingRequest).id,
152 status,
153 err: NO_MESSAGE_HANDLER,
154 };
155 return publish(noHandlerPacket);
156 }
157 return this.onProcessingStartHook(
158 this.transportId,
159 mqttContext,
160 async () => {
161 const response$ = this.transformToObservable(
162 await handler(packet.data, mqttContext),
163 );
164 response$ && this.send(response$, publish);
165 },
166 );
167 }
168
169 public getPublisher(
170 client: MqttClient,

Callers 1

getMessageHandlerMethod · 0.95

Calls 10

parseMessageMethod · 0.95
getPublisherMethod · 0.95
getHandlerByPatternMethod · 0.95
isUndefinedFunction · 0.90
transformToObservableMethod · 0.80
deserializeMethod · 0.65
handlerFunction · 0.50
toStringMethod · 0.45
handleEventMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected