From 1fe4dc2cad2ba28d0fc1f18b79ef5f8d06eb58cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Tue, 12 Nov 2024 12:35:25 +0100 Subject: [PATCH] fix(microservices): no messages emitted with mqtt when qos set #14079 --- packages/microservices/client/client-mqtt.ts | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/microservices/client/client-mqtt.ts b/packages/microservices/client/client-mqtt.ts index c2e7c6cf394..37d0b4284a6 100644 --- a/packages/microservices/client/client-mqtt.ts +++ b/packages/microservices/client/client-mqtt.ts @@ -210,15 +210,22 @@ export class ClientMqtt extends ClientProxy { return undefined; } - return { - ...requestOptions, - properties: { - ...requestOptions?.properties, + // Cant just spread objects as MQTT won't deliver + // any message with empty object as "userProperties" field + // @url https://github.com/nestjs/nest/issues/14079 + let options: MqttRecordOptions = {}; + if (requestOptions) { + options = { ...requestOptions }; + } + if (this.options?.userProperties) { + options.properties = { + ...options.properties, userProperties: { ...this.options?.userProperties, - ...requestOptions?.properties?.userProperties, + ...options.properties?.userProperties, }, - }, - }; + }; + } + return options; } }