From 0f2e4d64ad70713d7eb853a8ded5e55a848cd402 Mon Sep 17 00:00:00 2001 From: Tristan Nolde Date: Wed, 21 Jun 2023 17:29:27 +0200 Subject: [PATCH 1/2] docs(mqtt): description on how to set qos on subscriptions --- content/microservices/mqtt.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/content/microservices/mqtt.md b/content/microservices/mqtt.md index ea18eec810..da5abffa89 100644 --- a/content/microservices/mqtt.md +++ b/content/microservices/mqtt.md @@ -116,6 +116,33 @@ getTemperature(context) { } ``` +#### Quality of Service (QoS) + +Any subscription created with the `@MessagePattern` decorator will subscribe with QoS 0. If a higher QoS is required, it can be set globally using the `subscribeOptions` block when establishing the connection as follows: +```typescript +@@filename(main) +const app = await NestFactory.createMicroservice(AppModule, { + transport: Transport.MQTT, + options: { + url: 'mqtt://localhost:1883', + subscribeOptions: { + qos: 2 + }, + }, +}); +@@switch +const app = await NestFactory.createMicroservice(AppModule, { + transport: Transport.MQTT, + options: { + url: 'mqtt://localhost:1883', + subscribeOptions: { + qos: 2 + }, + }, +}); +``` +If a topic specific QoS is required, consider creating a [Custom transporter](https://docs.nestjs.com/microservices/custom-transport). + #### Record builders To configure message options (adjust the QoS level, set the Retain or DUP flags, or add additional properties to the payload), you can use the `MqttRecordBuilder` class. For example, to set `QoS` to `2` use the `setQoS` method, as follows: From 93b15b330c002d9ff3749efe37d8112818a8eea5 Mon Sep 17 00:00:00 2001 From: Kamil Mysliwiec Date: Tue, 2 Jul 2024 14:39:56 +0200 Subject: [PATCH 2/2] Update content/microservices/mqtt.md --- content/microservices/mqtt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/microservices/mqtt.md b/content/microservices/mqtt.md index da5abffa89..236e1ccd1f 100644 --- a/content/microservices/mqtt.md +++ b/content/microservices/mqtt.md @@ -118,7 +118,7 @@ getTemperature(context) { #### Quality of Service (QoS) -Any subscription created with the `@MessagePattern` decorator will subscribe with QoS 0. If a higher QoS is required, it can be set globally using the `subscribeOptions` block when establishing the connection as follows: +Any subscription created with `@MessagePattern` or `@EventPattern` decorators will subscribe with QoS 0. If a higher QoS is required, it can be set globally using the `subscribeOptions` block when establishing the connection as follows: ```typescript @@filename(main) const app = await NestFactory.createMicroservice(AppModule, {