Skip to content

[Feature] Replace MqttActor cmd-kind dispatch with match() #233

@pathosDev

Description

@pathosDev

Size / Priority

  • Size: S (~40 lines)
  • Category: C.1 Pattern-Matching.
  • Risk: low.

Affected files

  • src/io/broker/MqttActor.ts:240-251onReceive's cmd-kind dispatch.

Background

MqttActor is the MQTT 5.0 broker actor. Its command dispatch handles:

  • 'publish' — emit a PUBLISH packet.
  • 'subscribe' — emit a SUBSCRIBE packet.
  • 'unsubscribe' — emit UNSUBSCRIBE.
  • (potentially more, including user-property variants — verify during implementation).

Same pattern as #232 (JetStream): an if/else chain over discriminator strings. Adding a new cmd silently falls through without compile error.

Target code

import { match } from 'ts-pattern';

override onReceive(cmd: MqttCmd): void {
  match(cmd)
    .with({ kind: 'publish' },     (c) => this.handlePublish(c))
    .with({ kind: 'subscribe' },   (c) => this.handleSubscribe(c))
    .with({ kind: 'unsubscribe' }, (c) => this.handleUnsubscribe(c))
    .exhaustive();
}

Integration / risk

Test plan

  1. Regression — MQTT 5.0 test suite passes.
  2. Compile-time — new variant in the union produces error.
  3. MQTT integration — message round-trip through the broker still works.

Acceptance criteria

  • onReceive uses match().exhaustive().
  • Tests pass.
  • No behaviour drift on MQTT 5.0 user-properties / reason-codes.
  • No CHANGELOG entry needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority: lowNice-to-have / niche / demand-driven

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions