Skip to content

Allow per-message handlers for the operations #14

Description

@WiZeYAR

If we have:

...
channels:
  channel1:
    messages:
      Message1: ...
      Message2: ...
      Message3: ...
operations:
  op1:
    action: receive
    channel: { $ref: "#/channels/channel1" }
    ...
...

One would have to match over messages, while handling:

@app.consumer.op1
async def op(msg: Message1 | Message2 | Message3):
  match msg:
    case Message1():
      await handle1(msg)
    case Message2():
      await handle2(msg)
    case Message3():
      await handle2(msg)

We should move match logic to the level of the framework, having something like:

@app.consumer.op1(matches=(Message1, Message2))
async def handle12(msg: Message1 | Message2):
  ...

@app.consumer.op2(matches=[Message3])
async def handle3(msg: Message3):
  ...

The framework should raise a NotImplementedError, if at least one of the cases is unmatched during app.start call, and it must not allow two handlers for the same message-operation pair

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions