Skip to content

AsyncAPI v3: support receiving multiple messages per operation (follow-up to #140) #333

Closed

Description

@lerenn

Follow-up to #140. The send side of multiple-messages-per-operation shipped in #332 (PR), which generates one SendAs<Op>For<Message> function per message. This issue tracks the remaining receive side.

Goal

When an operation (or its channel) declares more than one message, generate a way to receive each message type. Per the agreed design:

  • API shape: per-message methods — e.g. SubscribeToXForUserCreated(ctx, fn func(ctx, UserCreatedMessage) error) and SubscribeToXForUserDeleted(...), one subscriber callback per message. Single-message operations stay unchanged.
  • Discrimination: try-each-until-valid — on receive, attempt to unmarshal + validate the raw broker message against each candidate message schema and dispatch to the first that fits. This is heuristic and can be ambiguous when schemas overlap (acknowledged trade-off).

Why it wasn't done in #332

The current controller tracks subscriptions in a map keyed by channel address with an "already subscribed" guard:

_, exists := c.subscriptions[addr]   // controller.tmpl
...
c.subscriptions[addr] = sub

Two per-message SubscribeToXForA / SubscribeToXForB calls on the same channel address would therefore collide. Supporting per-message receive requires reworking subscription management, for example one of:

  1. Key subscriptions by addr + message (allowing several broker subscriptions per channel, each filtering to its message type); or
  2. A single per-address subscription that multiplexes/dispatches to the registered per-message handlers.

Scope / acceptance

  • Per-message subscribe functions for multi-message operations (single-message unchanged, byte-identical output).
  • Try-each-until-valid discrimination on receive (unmarshal + validate).
  • Subscription-management rework so multiple per-message subscriptions on one channel don't collide.
  • Decide ack/nak semantics when a received message matches none of the expected types.
  • Regression test (ideally broker-backed in CI) covering dispatch of two distinct message types on one channel.

Notes

Channel.GetMessage was made deterministic in #332 and Operation.GetMessages() already returns all messages sorted by name, so the data layer is ready. The reply/request path with multiple messages is a further edge case to consider separately.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions