Skip to content

Commit d6586b4

Browse files
Merge pull request #2768 from TrisNol/patch-1
docs(mqtt): description on how to set qos on subscriptions
2 parents d89d241 + 93b15b3 commit d6586b4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

content/microservices/mqtt.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,33 @@ getTemperature(context) {
116116
}
117117
```
118118

119+
#### Quality of Service (QoS)
120+
121+
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:
122+
```typescript
123+
@@filename(main)
124+
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
125+
transport: Transport.MQTT,
126+
options: {
127+
url: 'mqtt://localhost:1883',
128+
subscribeOptions: {
129+
qos: 2
130+
},
131+
},
132+
});
133+
@@switch
134+
const app = await NestFactory.createMicroservice(AppModule, {
135+
transport: Transport.MQTT,
136+
options: {
137+
url: 'mqtt://localhost:1883',
138+
subscribeOptions: {
139+
qos: 2
140+
},
141+
},
142+
});
143+
```
144+
If a topic specific QoS is required, consider creating a [Custom transporter](https://docs.nestjs.com/microservices/custom-transport).
145+
119146
#### Record builders
120147

121148
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:

0 commit comments

Comments
 (0)