From c811951f5c198ecef006d7f694ace541e464a064 Mon Sep 17 00:00:00 2001
From: danbugs
Date: Mon, 28 Oct 2024 23:19:15 +0000
Subject: [PATCH] [pr feedback] added set-metadata method + revisited topic
Signed-off-by: danbugs
---
.github/workflows/main.yml | 2 +-
README.md | 2 +-
imports-request-reply.md | 21 ++++++++++++---------
imports.md | 19 +++++++++++--------
messaging-core.md | 23 +++++++++++++----------
messaging-request-reply.md | 25 ++++++++++++++-----------
wit/guest.wit | 4 ++--
wit/producer.wit | 4 ++--
wit/request-reply.wit | 2 +-
wit/types.wit | 6 +++---
10 files changed, 60 insertions(+), 48 deletions(-)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 45c37c2..7669187 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -13,5 +13,5 @@ jobs:
- uses: actions/checkout@v2
- uses: WebAssembly/wit-abi-up-to-date@v17
with:
- wit-bindgen: '0.30.0'
+ wit-bindgen: '0.34.0'
worlds: 'imports imports-request-reply messaging-core messaging-request-reply'
diff --git a/README.md b/README.md
index 01f7bbe..1d303b8 100644
--- a/README.md
+++ b/README.md
@@ -101,4 +101,4 @@ It would make sense for a lot of these functions to be asynchronous, but that is
the component model. Asynchronous support will be added as part of WASI Preview 3. When async support becomes
available, we plan to update the wasi-messaging interface to incorporate asynchronous patterns.
-> **Note**: Ensure you have version 0.30.0 of `wit-bindgen` installed to avoid compatibility issues.
+> **Note**: Ensure you have version 0.34.0 of `wit-bindgen` installed to avoid compatibility issues.
diff --git a/imports-request-reply.md b/imports-request-reply.md
index bdfa2d6..949b348 100644
--- a/imports-request-reply.md
+++ b/imports-request-reply.md
@@ -66,7 +66,6 @@ This allows the component to perform request/reply messaging patterns.
[constructor]message: func
Params
-topic
: string
data
: list<u8
>
Return values
@@ -83,13 +82,6 @@ This allows the component to perform request/reply messaging patterns.
-[method]message.set-topic: func
-Set the topic/subject/channel this message should be sent on
-Params
-
[method]message.content-type: func
An optional content-type describing the format of the data in the message. This is
sometimes described as the "format" type
@@ -145,6 +137,13 @@ message
key
: string
value
: string
+[method]message.set-metadata: func
+Set the metadata
+Params
+
[method]message.remove-metadata: func
Remove a key-value pair from the metadata
Params
@@ -216,7 +215,7 @@ return the list of messages received up to that point.
result<list<own<message
>>, error
>
reply: func
-Replies to the given message with the given response message. The details of which channel
+
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
handled in the best way possible for the underlying messaging system.
Please note that this reply functionality is different than something like HTTP because there
@@ -247,6 +246,9 @@ where the reply is sent and the connection is closed.
#### `type error`
[`error`](#error)
+#### `type topic`
+[`topic`](#topic)
+
----
Functions
send: func
@@ -255,6 +257,7 @@ where the reply is sent and the connection is closed.
Return values
diff --git a/imports.md b/imports.md
index 5e16128..419b568 100644
--- a/imports.md
+++ b/imports.md
@@ -65,7 +65,6 @@ It includes the producer
interface for sending messages.
[constructor]message: func
Params
-topic
: string
data
: list<u8
>
Return values
@@ -82,13 +81,6 @@ It includes the producer
interface for sending messages.
-[method]message.set-topic: func
-Set the topic/subject/channel this message should be sent on
-Params
-
[method]message.content-type: func
An optional content-type describing the format of the data in the message. This is
sometimes described as the "format" type
@@ -144,6 +136,13 @@ message
key
: string
value
: string
+[method]message.set-metadata: func
+Set the metadata
+Params
+
[method]message.remove-metadata: func
Remove a key-value pair from the metadata
Params
@@ -164,6 +163,9 @@ message
#### `type error`
[`error`](#error)
+#### `type topic`
+[`topic`](#topic)
+
----
Functions
send: func
@@ -172,6 +174,7 @@ message
Return values
diff --git a/messaging-core.md b/messaging-core.md
index e20f1cd..5a0de6c 100644
--- a/messaging-core.md
+++ b/messaging-core.md
@@ -70,7 +70,6 @@ enabling the component to handle incoming messages without request/reply capabil
[constructor]message: func
Params
-topic
: string
data
: list<u8
>
Return values
@@ -87,13 +86,6 @@ enabling the component to handle incoming messages without request/reply capabil
-[method]message.set-topic: func
-Set the topic/subject/channel this message should be sent on
-Params
-
[method]message.content-type: func
An optional content-type describing the format of the data in the message. This is
sometimes described as the "format" type
@@ -149,6 +141,13 @@ message
key
: string
value
: string
+[method]message.set-metadata: func
+Set the metadata
+Params
+
[method]message.remove-metadata: func
Remove a key-value pair from the metadata
Params
@@ -169,6 +168,9 @@ message
#### `type error`
[`error`](#error)
+#### `type topic`
+[`topic`](#topic)
+
----
Functions
send: func
@@ -177,6 +179,7 @@ message
Return values
@@ -198,7 +201,7 @@ message
Functions
handle: func
Whenever this guest receives a message in one of the subscribed topics, the message is
-sent to this handler. The guest is responsible for matching on the channel and handling the
+sent to this handler. The guest is responsible for matching on the topic and handling the
message accordingly. Implementors (such as hosts) calling this interface should make their
own decisions on how to handle errors returned from this function.
Params
@@ -211,7 +214,7 @@ own decisions on how to handle errors returned from this function.
get-topics: func
Returns a list of topics (represented as string
s) at runtime the guest should be subscribed
-to at runtime. Implementors should consider also allowing subscriptions to be made at compile time
+Implementors should consider also allowing subscriptions to be made at compile time
via some sort of configuration file. This function is intended to be called at the start of the
guest's lifecycle before any messages are sent.
Return values
diff --git a/messaging-request-reply.md b/messaging-request-reply.md
index f2ec63c..6dff9b8 100644
--- a/messaging-request-reply.md
+++ b/messaging-request-reply.md
@@ -72,7 +72,6 @@ handling incoming messages with request/reply capabilities.
[constructor]message: func
Params
-topic
: string
data
: list<u8
>
Return values
@@ -89,13 +88,6 @@ handling incoming messages with request/reply capabilities.
-[method]message.set-topic: func
-Set the topic/subject/channel this message should be sent on
-Params
-
[method]message.content-type: func
An optional content-type describing the format of the data in the message. This is
sometimes described as the "format" type
@@ -151,6 +143,13 @@ message
key
: string
value
: string
+[method]message.set-metadata: func
+Set the metadata
+Params
+
[method]message.remove-metadata: func
Remove a key-value pair from the metadata
Params
@@ -222,7 +221,7 @@ return the list of messages received up to that point.
result<list<own<message
>>, error
>
reply: func
-Replies to the given message with the given response message. The details of which channel
+
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
handled in the best way possible for the underlying messaging system.
Please note that this reply functionality is different than something like HTTP because there
@@ -253,6 +252,9 @@ where the reply is sent and the connection is closed.
#### `type error`
[`error`](#error)
+#### `type topic`
+[`topic`](#topic)
+
----
Functions
send: func
@@ -261,6 +263,7 @@ where the reply is sent and the connection is closed.
Return values
@@ -282,7 +285,7 @@ where the reply is sent and the connection is closed.
Functions
handle: func
Whenever this guest receives a message in one of the subscribed topics, the message is
-sent to this handler. The guest is responsible for matching on the channel and handling the
+sent to this handler. The guest is responsible for matching on the topic and handling the
message accordingly. Implementors (such as hosts) calling this interface should make their
own decisions on how to handle errors returned from this function.
Params
@@ -295,7 +298,7 @@ own decisions on how to handle errors returned from this function.
get-topics: func
Returns a list of topics (represented as string
s) at runtime the guest should be subscribed
-to at runtime. Implementors should consider also allowing subscriptions to be made at compile time
+Implementors should consider also allowing subscriptions to be made at compile time
via some sort of configuration file. This function is intended to be called at the start of the
guest's lifecycle before any messages are sent.
Return values
diff --git a/wit/guest.wit b/wit/guest.wit
index 940bb31..29c916d 100644
--- a/wit/guest.wit
+++ b/wit/guest.wit
@@ -2,13 +2,13 @@ interface incoming-handler {
use types.{message, error, topic};
/// Whenever this guest receives a message in one of the subscribed topics, the message is
- /// sent to this handler. The guest is responsible for matching on the channel and handling the
+ /// sent to this handler. The guest is responsible for matching on the topic and handling the
/// message accordingly. Implementors (such as hosts) calling this interface should make their
/// own decisions on how to handle errors returned from this function.
handle: func(message: message) -> result<_, error>;
// Returns a list of topics (represented as `string`s) at runtime the guest should be subscribed
- // to at runtime. Implementors should consider also allowing subscriptions to be made at compile time
+ // Implementors should consider also allowing subscriptions to be made at compile time
// via some sort of configuration file. This function is intended to be called at the start of the
// guest's lifecycle before any messages are sent.
get-topics: func() -> result, error>;
diff --git a/wit/producer.wit b/wit/producer.wit
index 86c509d..9c86915 100644
--- a/wit/producer.wit
+++ b/wit/producer.wit
@@ -1,7 +1,7 @@
/// The producer interface is used to send messages to a channel/topic.
interface producer {
- use types.{client, message, error};
+ use types.{client, message, error, topic};
/// Sends the message using the given client.
- send: func(c: borrow, message: message) -> result<_, error>;
+ send: func(c: borrow, message: message, topic: topic) -> result<_, error>;
}
diff --git a/wit/request-reply.wit b/wit/request-reply.wit
index 8fe8031..da8a543 100644
--- a/wit/request-reply.wit
+++ b/wit/request-reply.wit
@@ -33,7 +33,7 @@ interface request-reply {
/// return the list of messages received up to that point.
request: func(c: borrow, message: borrow, options: option) -> result, error>;
- /// Replies to the given message with the given response message. The details of which channel
+ /// 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
/// handled in the best way possible for the underlying messaging system.
///
diff --git a/wit/types.wit b/wit/types.wit
index 0c0b82b..5c0b417 100644
--- a/wit/types.wit
+++ b/wit/types.wit
@@ -25,11 +25,9 @@ interface types {
/// A message with a binary payload and additional information
resource message {
- constructor(topic: string, data: list);
+ constructor(data: list);
/// The topic/subject/channel this message was received or should be sent on
topic: func() -> topic;
- /// Set the topic/subject/channel this message should be sent on
- set-topic: func(topic: topic);
/// 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;
@@ -45,6 +43,8 @@ interface types {
metadata: func() -> option;
/// Add a new key-value pair to the metadata, overwriting any existing value for the same key
add-metadata: func(key: string, value: string);
+ /// Set the metadata
+ set-metadata: func(meta: metadata);
/// Remove a key-value pair from the metadata
remove-metadata: func(key: string);
}