Skip to content

Commit a9a302e

Browse files
Merge pull request #3383 from suuuuuuminnnnnn/docs/mqtt-per-pattern-qos
docs(microservices): document mqtt pattern qos
2 parents 326e89e + 700be66 commit a9a302e

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

content/microservices/mqtt.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,36 @@ const app = await NestFactory.createMicroservice(AppModule, {
143143
});
144144
```
145145

146-
If a topic specific QoS is required, consider creating a [Custom transporter](https://docs.nestjs.com/microservices/custom-transport).
146+
#### Per-pattern QoS
147+
148+
You can override the MQTT subscription QoS on a per-pattern basis by providing `qos` in the `extras` field of the pattern decorator. When not specified, the global `subscribeOptions.qos` is used as the default.
149+
150+
```typescript
151+
@@filename()
152+
@EventPattern('critical-events', { extras: { qos: 2 } })
153+
handleCriticalEvent(@Payload() data: any) {
154+
// This subscription uses QoS 2
155+
}
156+
157+
@EventPattern('metrics', { extras: { qos: 0 } })
158+
handleMetrics(@Payload() data: any) {
159+
// This subscription uses QoS 0
160+
}
161+
@@switch
162+
@Bind(Payload())
163+
@EventPattern('critical-events', { extras: { qos: 2 } })
164+
handleCriticalEvent(data) {
165+
// This subscription uses QoS 2
166+
}
167+
168+
@Bind(Payload())
169+
@EventPattern('metrics', { extras: { qos: 0 } })
170+
handleMetrics(data) {
171+
// This subscription uses QoS 0
172+
}
173+
```
174+
175+
> info **Hint** Per-pattern QoS configuration does not affect existing behavior. When `extras.qos` is not specified, the subscription uses the global `subscribeOptions.qos` value.
147176
148177
#### Record builders
149178

0 commit comments

Comments
 (0)