Skip to content

Commit

Permalink
Merge pull request #2768 from TrisNol/patch-1
Browse files Browse the repository at this point in the history
docs(mqtt): description on how to set qos on subscriptions
  • Loading branch information
kamilmysliwiec authored Jul 2, 2024
2 parents d89d241 + 93b15b3 commit d6586b4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions content/microservices/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,33 @@ getTemperature(context) {
}
```

#### Quality of Service (QoS)

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<MicroserviceOptions>(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:
Expand Down

0 comments on commit d6586b4

Please sign in to comment.