From 4ee59bb881f7a8675fbb3ae7ca5d5d586ab88657 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Wed, 4 Dec 2024 19:09:30 +0100 Subject: [PATCH] fix: message `topic` usage (#28) * fix(request-reply): specify request topic Signed-off-by: Roman Volosatovs * refactor(types): make `topic` method return an option Topic can only ever be set by the host, for messages originating in the guest it cannot be set, therefore make the getter return an optional value for the cases where the is no topic to return. Signed-off-by: Roman Volosatovs * chore: regenerate documentation Signed-off-by: Roman Volosatovs --------- Signed-off-by: Roman Volosatovs --- imports-request-reply.md | 8 ++++++-- imports.md | 4 ++-- messaging-core.md | 4 ++-- messaging-request-reply.md | 8 ++++++-- wit/request-reply.wit | 4 ++-- wit/types.wit | 4 ++-- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/imports-request-reply.md b/imports-request-reply.md index d36307e..84063a7 100644 --- a/imports-request-reply.md +++ b/imports-request-reply.md @@ -73,14 +73,14 @@ This allows the component to perform request/reply messaging patterns.

  • own<message>
  • [method]message.topic: func

    -

    The topic/subject/channel this message was received on

    +

    The topic/subject/channel this message was received on, if any

    Params
    Return values

    [method]message.content-type: func

    An optional content-type describing the format of the data in the message. This is @@ -168,6 +168,9 @@ included it as a core interface.

    #### `type error` [`error`](#error)

    +#### `type topic` +[`topic`](#topic) +

    #### `resource request-options`

    Options for a request/reply operation. This is a resource to allow for future expansion of options.

    @@ -208,6 +211,7 @@ return the list of messages received up to that point.

    Params
    diff --git a/imports.md b/imports.md index 2900330..3f09021 100644 --- a/imports.md +++ b/imports.md @@ -72,14 +72,14 @@ It includes the producer interface for sending messages.

  • own<message>
  • [method]message.topic: func

    -

    The topic/subject/channel this message was received on

    +

    The topic/subject/channel this message was received on, if any

    Params
    Return values

    [method]message.content-type: func

    An optional content-type describing the format of the data in the message. This is diff --git a/messaging-core.md b/messaging-core.md index 1302613..dd6d715 100644 --- a/messaging-core.md +++ b/messaging-core.md @@ -77,14 +77,14 @@ enabling the component to handle incoming messages without request/reply capabil

  • own<message>
  • [method]message.topic: func

    -

    The topic/subject/channel this message was received on

    +

    The topic/subject/channel this message was received on, if any

    Params
    Return values

    [method]message.content-type: func

    An optional content-type describing the format of the data in the message. This is diff --git a/messaging-request-reply.md b/messaging-request-reply.md index 37d61c0..e9b9abd 100644 --- a/messaging-request-reply.md +++ b/messaging-request-reply.md @@ -79,14 +79,14 @@ handling incoming messages with request/reply capabilities.

  • own<message>
  • [method]message.topic: func

    -

    The topic/subject/channel this message was received on

    +

    The topic/subject/channel this message was received on, if any

    Params
    Return values

    [method]message.content-type: func

    An optional content-type describing the format of the data in the message. This is @@ -174,6 +174,9 @@ included it as a core interface.

    #### `type error` [`error`](#error)

    +#### `type topic` +[`topic`](#topic) +

    #### `resource request-options`

    Options for a request/reply operation. This is a resource to allow for future expansion of options.

    @@ -214,6 +217,7 @@ return the list of messages received up to that point.

    Params
    diff --git a/wit/request-reply.wit b/wit/request-reply.wit index da8a543..7467d76 100644 --- a/wit/request-reply.wit +++ b/wit/request-reply.wit @@ -3,7 +3,7 @@ /// request/reply. However, request/reply is a very common pattern in messaging and as such, we have /// included it as a core interface. interface request-reply { - use types.{client, message, error}; + use types.{client, message, error, topic}; /// Options for a request/reply operation. This is a resource to allow for future expansion of /// options. @@ -31,7 +31,7 @@ interface request-reply { /// error, (2) if the maximum expected number of replies were received before timeout, return /// the list of messages, or (3) if the timeout is reached before the expected number of replies, /// return the list of messages received up to that point. - request: func(c: borrow, message: borrow, options: option) -> result, error>; + request: func(c: borrow, topic: topic, message: borrow, options: option) -> result, error>; /// Replies to the given message with the given response message. The details of which topic /// the message is sent to is up to the implementation. This allows for reply-to details to be diff --git a/wit/types.wit b/wit/types.wit index d7e8292..62f02f7 100644 --- a/wit/types.wit +++ b/wit/types.wit @@ -26,8 +26,8 @@ interface types { /// A message with a binary payload and additional information resource message { constructor(data: list); - /// The topic/subject/channel this message was received on - topic: func() -> topic; + /// The topic/subject/channel this message was received on, if any + topic: func() -> option; /// An optional content-type describing the format of the data in the message. This is /// sometimes described as the "format" type content-type: func() -> option;