Skip to content

Conversation

@suuuuuuminnnnnn
Copy link
Contributor

@suuuuuuminnnnnn suuuuuuminnnnnn commented Feb 3, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

MQTT subscriptions are currently created using only the global subscribeOptions (including qos) when ServerMqtt binds handlers.
This means all patterns share the same QoS and there is no way to override QoS per handler/pattern.

Issue Number: #16239

What is the new behavior?

Handlers can now override the QoS used for their MQTT subscription by providing extras.qos on the pattern decorator.
If extras.qos is defined, it overrides only the qos field for that specific pattern; otherwise the global subscribeOptions behavior remains unchanged.

Example:

@EventPattern('alerts/critical', Transport.MQTT, { qos: 2 })
handleCriticalAlert(data: any) {
  // high priority - guaranteed delivery
}

@EventPattern('telemetry/metrics', Transport.MQTT, { qos: 0 })
handleMetrics(data: any) {
  // best-effort delivery
}

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Implementation details

  • Per-pattern subscribe options are computed by merging the global subscribeOptions with handler extras,
    overriding only qos when extras.qos is defined.
  • No behavior changes when extras.qos is not provided.

Tests

  • Added/updated tests to verify:
    • extras.qos overrides global QoS for that pattern
    • patterns without extras.qos use the global subscribe options
    • multiple patterns can subscribe with different QoS values

How to verify

  • Run the microservices test suite, or the specific MQTT spec added in this PR.

@coveralls
Copy link

Pull Request Test Coverage Report for Build c12742ef-743b-442c-9eb2-150835a5ac57

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 89.829%

Totals Coverage Status
Change from base Build 3e932a26-d0f7-4368-b102-196754d847cf: 0.004%
Covered Lines: 7463
Relevant Lines: 8308

💛 - Coveralls

@kamilmysliwiec
Copy link
Member

Could you create a PR to the docs to reflect/showcase this feature?

@kamilmysliwiec kamilmysliwiec merged commit db90c3f into nestjs:master Feb 3, 2026
2 checks passed
@suuuuuuminnnnnn
Copy link
Contributor Author

Thanks for the suggestion!

I’m happy to add docs, but before I open a PR: where would you prefer this to be documented?
My guess is either:

  • the Microservices MQTT transport docs (mentioning that extras.qos can override the global subscribeOptions.qos per pattern), or
  • an example snippet in the @EventPattern / @MessagePattern section for MQTT.

If you point me to the preferred page/section, I can prepare a small doc update that explains the behavior and includes a short example.

@kamilmysliwiec
Copy link
Member

in the Microservices MQTT transport docs correct

@kamilmysliwiec
Copy link
Member

just a tiny additional section somewhere at the bottom of the page would be nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants