Skip to content

Commit aa19481

Browse files
feat(*): Additional changes to request/reply for streamlining
Also removes the channel parameter I forgot to remove in a previous commit Signed-off-by: Taylor Thomas <[email protected]>
1 parent 536043d commit aa19481

File tree

8 files changed

+118
-293
lines changed

8 files changed

+118
-293
lines changed

imports-request-reply.md

Lines changed: 52 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<p><a name="error.unauthorized"></a><code>unauthorized</code></p>
2323
<p>The requested option is not authorized. This could be a topic it doesn't have
2424
permission to subscribe to, or a permission it doesn't have to perform a specific
25-
action. This error is mainly used when calling `update-config`.
25+
action. This error is mainly used when calling `set-subscriptions` on a guest.
2626
</li>
2727
<li>
2828
<p><a name="error.timeout"></a><code>timeout</code></p>
@@ -33,22 +33,14 @@ action. This error is mainly used when calling `update-config`.
3333
<p>An error occurred with the connection. Includes a message for additional context
3434
</li>
3535
<li>
36+
<p><a name="error.abandoned"></a><code>abandoned</code>: <code>string</code></p>
37+
<p>Work on the message was abandoned for the given reason
38+
</li>
39+
<li>
3640
<p><a name="error.other"></a><code>other</code>: <code>string</code></p>
3741
<p>A catch all for other types of errors
3842
</li>
3943
</ul>
40-
<h4><a name="channel"></a><code>type channel</code></h4>
41-
<p><code>string</code></p>
42-
<p>There are two types of channels:
43-
- publish-subscribe channel, which is a broadcast channel, and
44-
- point-to-point channel, which is a unicast channel.
45-
<p>The interface doesn't highlight this difference in the type itself as that's uniquely a consumer issue.</p>
46-
<h4><a name="config"></a><code>record config</code></h4>
47-
<p>Configuration includes a required list of channels the guest is subscribing to</p>
48-
<h5>Record Fields</h5>
49-
<ul>
50-
<li><a name="config.channels"></a><code>channels</code>: list&lt;<a href="#channel"><a href="#channel"><code>channel</code></a></a>&gt;</li>
51-
</ul>
5244
<h4><a name="message"></a><code>resource message</code></h4>
5345
<h2>A message with a binary payload and additional information</h2>
5446
<h3>Functions</h3>
@@ -64,10 +56,8 @@ action. This error is mainly used when calling `update-config`.
6456
<h4><a name="constructor_message"></a><code>[constructor]message: func</code></h4>
6557
<h5>Params</h5>
6658
<ul>
67-
<li><a name="constructor_message.topic"></a><code>topic</code>: <a href="#channel"><a href="#channel"><code>channel</code></a></a></li>
59+
<li><a name="constructor_message.topic"></a><code>topic</code>: <code>string</code></li>
6860
<li><a name="constructor_message.data"></a><code>data</code>: list&lt;<code>u8</code>&gt;</li>
69-
<li><a name="constructor_message.content_type"></a><code>content-type</code>: option&lt;<code>string</code>&gt;</li>
70-
<li><a name="constructor_message.metadata"></a><code>metadata</code>: option&lt;list&lt;(<code>string</code>, <code>string</code>)&gt;&gt;</li>
7161
</ul>
7262
<h5>Return values</h5>
7363
<ul>
@@ -81,14 +71,14 @@ action. This error is mainly used when calling `update-config`.
8171
</ul>
8272
<h5>Return values</h5>
8373
<ul>
84-
<li><a name="method_message.topic.0"></a> <a href="#channel"><a href="#channel"><code>channel</code></a></a></li>
74+
<li><a name="method_message.topic.0"></a> <code>string</code></li>
8575
</ul>
8676
<h4><a name="method_message.set_topic"></a><code>[method]message.set-topic: func</code></h4>
8777
<p>Set the topic/subject/channel this message should be sent on</p>
8878
<h5>Params</h5>
8979
<ul>
9080
<li><a name="method_message.set_topic.self"></a><code>self</code>: borrow&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
91-
<li><a name="method_message.set_topic.topic"></a><code>topic</code>: <a href="#channel"><a href="#channel"><code>channel</code></a></a></li>
81+
<li><a name="method_message.set_topic.topic"></a><code>topic</code>: <code>string</code></li>
9282
</ul>
9383
<h4><a name="method_message.content_type"></a><code>[method]message.content-type: func</code></h4>
9484
<p>An optional content-type describing the format of the data in the message. This is
@@ -145,46 +135,6 @@ message</p>
145135
<li><a name="method_message.add_metadata.key"></a><code>key</code>: <code>string</code></li>
146136
<li><a name="method_message.add_metadata.value"></a><code>value</code>: <code>string</code></li>
147137
</ul>
148-
<h4><a name="method_message.complete"></a><code>[method]message.complete: func</code></h4>
149-
<p>Completes/acks the message</p>
150-
<p>A message can exist under several statuses:
151-
(1) available: the message is ready to be read,
152-
(2) acquired: the message has been sent to a consumer (but still exists in the queue),
153-
(3) accepted (result of complete): the message has been received and ACK-ed by a consumer and can be safely removed from the queue,
154-
(4) rejected (result of abandon): the message has been received and NACK-ed by a consumer, at which point it can be:</p>
155-
<ul>
156-
<li>deleted,</li>
157-
<li>sent to a dead-letter queue, or</li>
158-
<li>kept in the queue for further processing.</li>
159-
</ul>
160-
<h5>Params</h5>
161-
<ul>
162-
<li><a name="method_message.complete.self"></a><code>self</code>: borrow&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
163-
</ul>
164-
<h5>Return values</h5>
165-
<ul>
166-
<li><a name="method_message.complete.0"></a> result&lt;_, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
167-
</ul>
168-
<h4><a name="method_message.abandon"></a><code>[method]message.abandon: func</code></h4>
169-
<p>Abandon/nacks the message</p>
170-
<p>A message can exist under several statuses:
171-
(1) available: the message is ready to be read,
172-
(2) acquired: the message has been sent to a consumer (but still exists in the queue),
173-
(3) accepted (result of complete): the message has been received and ACK-ed by a consumer and can be safely removed from the queue,
174-
(4) rejected (result of abandon): the message has been received and NACK-ed by a consumer, at which point it can be:</p>
175-
<ul>
176-
<li>deleted,</li>
177-
<li>sent to a dead-letter queue, or</li>
178-
<li>kept in the queue for further processing.</li>
179-
</ul>
180-
<h5>Params</h5>
181-
<ul>
182-
<li><a name="method_message.abandon.self"></a><code>self</code>: borrow&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
183-
</ul>
184-
<h5>Return values</h5>
185-
<ul>
186-
<li><a name="method_message.abandon.0"></a> result&lt;_, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
187-
</ul>
188138
<h2><a name="wasi:messaging_request_reply_0.2.0_draft"></a>Import interface wasi:messaging/[email protected]</h2>
189139
<p>The request-reply interface allows a guest to send a message and await a response. This
190140
interface is considered optional as not all message services support the concept of
@@ -201,20 +151,53 @@ included it as a core interface.</p>
201151
#### <a name="error"></a>`type error`
202152
[`error`](#error)
203153
<p>
204-
----
154+
#### <a name="request_options"></a>`resource request-options`
155+
<h2>Options for a request/reply operation. This is a resource to allow for future expansion of
156+
options.</h2>
205157
<h3>Functions</h3>
158+
<h4><a name="constructor_request_options"></a><code>[constructor]request-options: func</code></h4>
159+
<p>Creates a new request options resource with no options set.</p>
160+
<h5>Return values</h5>
161+
<ul>
162+
<li><a name="constructor_request_options.0"></a> own&lt;<a href="#request_options"><a href="#request_options"><code>request-options</code></a></a>&gt;</li>
163+
</ul>
164+
<h4><a name="method_request_options.set_timeout_ms"></a><code>[method]request-options.set-timeout-ms: func</code></h4>
165+
<p>The maximum amount of time to wait for a response. If the timeout value is not set, then
166+
the request/reply operation will block until a message is received in response.</p>
167+
<h5>Params</h5>
168+
<ul>
169+
<li><a name="method_request_options.set_timeout_ms.self"></a><code>self</code>: borrow&lt;<a href="#request_options"><a href="#request_options"><code>request-options</code></a></a>&gt;</li>
170+
<li><a name="method_request_options.set_timeout_ms.timeout_ms"></a><code>timeout-ms</code>: <code>u32</code></li>
171+
</ul>
206172
<h4><a name="request"></a><code>request: func</code></h4>
207-
<p>Performs a blocking request/reply operation with an optional timeout. If the timeout value
208-
is not set, then the request/reply operation will block indefinitely.</p>
173+
<p>Performs a blocking request/reply operation with an optional set of request options. This
174+
returns only the first reply received or a timeout . If more than one reply is expected, then the
175+
<a href="#request_multi"><code>request-multi</code></a> function should be used instead.</p>
209176
<h5>Params</h5>
210177
<ul>
211-
<li><a name="request.c"></a><code>c</code>: own&lt;<a href="#client"><a href="#client"><code>client</code></a></a>&gt;</li>
178+
<li><a name="request.c"></a><code>c</code>: borrow&lt;<a href="#client"><a href="#client"><code>client</code></a></a>&gt;</li>
212179
<li><a name="request.msg"></a><code>msg</code>: own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
213-
<li><a name="request.timeout_ms"></a><code>timeout-ms</code>: option&lt;<code>u32</code>&gt;</li>
180+
<li><a name="request.opts"></a><code>opts</code>: option&lt;own&lt;<a href="#request_options"><a href="#request_options"><code>request-options</code></a></a>&gt;&gt;</li>
181+
</ul>
182+
<h5>Return values</h5>
183+
<ul>
184+
<li><a name="request.0"></a> result&lt;own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
185+
</ul>
186+
<h4><a name="request_multi"></a><code>request-multi: func</code></h4>
187+
<p>Performs a blocking request/reply operation with an optional set of request options. This
188+
returns all replies received up to the number of expected replies. It is recommended to use
189+
a <a href="#request_options"><code>request-options</code></a> with the timeout set to ensure that the operation does not block
190+
indefinitely.</p>
191+
<h5>Params</h5>
192+
<ul>
193+
<li><a name="request_multi.c"></a><code>c</code>: borrow&lt;<a href="#client"><a href="#client"><code>client</code></a></a>&gt;</li>
194+
<li><a name="request_multi.msg"></a><code>msg</code>: own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
195+
<li><a name="request_multi.expected_replies"></a><code>expected-replies</code>: <code>u32</code></li>
196+
<li><a name="request_multi.opts"></a><code>opts</code>: option&lt;own&lt;<a href="#request_options"><a href="#request_options"><code>request-options</code></a></a>&gt;&gt;</li>
214197
</ul>
215198
<h5>Return values</h5>
216199
<ul>
217-
<li><a name="request.0"></a> result&lt;option&lt;list&lt;own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;&gt;&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
200+
<li><a name="request_multi.0"></a> result&lt;list&lt;own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
218201
</ul>
219202
<h4><a name="reply"></a><code>reply: func</code></h4>
220203
<p>Replies to the given message with the given response message. The details of which channel
@@ -236,9 +219,6 @@ handled in the best way possible for the underlying messaging system.</p>
236219
<h4><a name="client"></a><code>type client</code></h4>
237220
<p><a href="#client"><a href="#client"><code>client</code></a></a></p>
238221
<p>
239-
#### <a name="channel"></a>`type channel`
240-
[`channel`](#channel)
241-
<p>
242222
#### <a name="message"></a>`type message`
243223
[`message`](#message)
244224
<p>
@@ -248,12 +228,10 @@ handled in the best way possible for the underlying messaging system.</p>
248228
----
249229
<h3>Functions</h3>
250230
<h4><a name="send"></a><code>send: func</code></h4>
251-
<p>Sends a message to the given channel/topic. If the channel/topic is not empty, it will
252-
override the channel/topic in the message.</p>
231+
<p>Sends the message using the given client.</p>
253232
<h5>Params</h5>
254233
<ul>
255234
<li><a name="send.c"></a><code>c</code>: own&lt;<a href="#client"><a href="#client"><code>client</code></a></a>&gt;</li>
256-
<li><a name="send.ch"></a><code>ch</code>: <a href="#channel"><a href="#channel"><code>channel</code></a></a></li>
257235
<li><a name="send.m"></a><code>m</code>: own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
258236
</ul>
259237
<h5>Return values</h5>
@@ -267,18 +245,10 @@ override the channel/topic in the message.</p>
267245
<h4><a name="error"></a><code>type error</code></h4>
268246
<p><a href="#error"><a href="#error"><code>error</code></a></a></p>
269247
<p>
270-
#### <a name="config"></a>`type config`
271-
[`config`](#config)
272-
<p>
273248
----
274249
<h3>Functions</h3>
275-
<h4><a name="update_config"></a><code>update-config: func</code></h4>
276-
<p>'Fit-all' type function for updating a guest's configuration – this could be useful for:</p>
277-
<ul>
278-
<li>unsubscribing from a channel,</li>
279-
<li>checkpointing,</li>
280-
<li>etc..</li>
281-
</ul>
250+
<h4><a name="set_subscriptions"></a><code>set-subscriptions: func</code></h4>
251+
<p>Set the current subscriptions for this guest.</p>
282252
<p>Please note that implementations that provide <code>wasi:messaging</code> are responsible for ensuring
283253
that guests are not allowed to subscribe to channels that they are not configured to
284254
subscribe to (or have access to). Failure to do so can result in possible breakout or access
@@ -287,9 +257,9 @@ should validate that the configured topics are valid topics the guest should hav
287257
enforce it via the credentials used to connect to the service.</p>
288258
<h5>Params</h5>
289259
<ul>
290-
<li><a name="update_config.gc"></a><code>gc</code>: <a href="#config"><a href="#config"><code>config</code></a></a></li>
260+
<li><a name="set_subscriptions.topics"></a><code>topics</code>: list&lt;<code>string</code>&gt;</li>
291261
</ul>
292262
<h5>Return values</h5>
293263
<ul>
294-
<li><a name="update_config.0"></a> result&lt;_, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
264+
<li><a name="set_subscriptions.0"></a> result&lt;_, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
295265
</ul>

0 commit comments

Comments
 (0)