Skip to content

Commit 4ee59bb

Browse files
authored
fix: message topic usage (#28)
* fix(request-reply): specify request topic Signed-off-by: Roman Volosatovs <[email protected]> * 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 <[email protected]> * chore: regenerate documentation Signed-off-by: Roman Volosatovs <[email protected]> --------- Signed-off-by: Roman Volosatovs <[email protected]>
1 parent 55c13e8 commit 4ee59bb

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

imports-request-reply.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ This allows the component to perform request/reply messaging patterns.</p>
7373
<li><a id="constructor_message.0"></a> own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
7474
</ul>
7575
<h4><a id="method_message_topic"></a><code>[method]message.topic: func</code></h4>
76-
<p>The topic/subject/channel this message was received on</p>
76+
<p>The topic/subject/channel this message was received on, if any</p>
7777
<h5>Params</h5>
7878
<ul>
7979
<li><a id="method_message_topic.self"></a><code>self</code>: borrow&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
8080
</ul>
8181
<h5>Return values</h5>
8282
<ul>
83-
<li><a id="method_message_topic.0"></a> <a href="#topic"><a href="#topic"><code>topic</code></a></a></li>
83+
<li><a id="method_message_topic.0"></a> option&lt;<a href="#topic"><a href="#topic"><code>topic</code></a></a>&gt;</li>
8484
</ul>
8585
<h4><a id="method_message_content_type"></a><code>[method]message.content-type: func</code></h4>
8686
<p>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.</p>
168168
#### <a id="error"></a>`type error`
169169
[`error`](#error)
170170
<p>
171+
#### <a id="topic"></a>`type topic`
172+
[`topic`](#topic)
173+
<p>
171174
#### <a id="request_options"></a>`resource request-options`
172175
<h2>Options for a request/reply operation. This is a resource to allow for future expansion of
173176
options.</h2>
@@ -208,6 +211,7 @@ return the list of messages received up to that point.</p>
208211
<h5>Params</h5>
209212
<ul>
210213
<li><a id="request.c"></a><code>c</code>: borrow&lt;<a href="#client"><a href="#client"><code>client</code></a></a>&gt;</li>
214+
<li><a id="request.topic"></a><a href="#topic"><code>topic</code></a>: <a href="#topic"><a href="#topic"><code>topic</code></a></a></li>
211215
<li><a id="request.message"></a><a href="#message"><code>message</code></a>: borrow&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
212216
<li><a id="request.options"></a><code>options</code>: option&lt;own&lt;<a href="#request_options"><a href="#request_options"><code>request-options</code></a></a>&gt;&gt;</li>
213217
</ul>

imports.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ It includes the <code>producer</code> interface for sending messages.</p>
7272
<li><a id="constructor_message.0"></a> own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
7373
</ul>
7474
<h4><a id="method_message_topic"></a><code>[method]message.topic: func</code></h4>
75-
<p>The topic/subject/channel this message was received on</p>
75+
<p>The topic/subject/channel this message was received on, if any</p>
7676
<h5>Params</h5>
7777
<ul>
7878
<li><a id="method_message_topic.self"></a><code>self</code>: borrow&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
7979
</ul>
8080
<h5>Return values</h5>
8181
<ul>
82-
<li><a id="method_message_topic.0"></a> <a href="#topic"><a href="#topic"><code>topic</code></a></a></li>
82+
<li><a id="method_message_topic.0"></a> option&lt;<a href="#topic"><a href="#topic"><code>topic</code></a></a>&gt;</li>
8383
</ul>
8484
<h4><a id="method_message_content_type"></a><code>[method]message.content-type: func</code></h4>
8585
<p>An optional content-type describing the format of the data in the message. This is

messaging-core.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ enabling the component to handle incoming messages without request/reply capabil
7777
<li><a id="constructor_message.0"></a> own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
7878
</ul>
7979
<h4><a id="method_message_topic"></a><code>[method]message.topic: func</code></h4>
80-
<p>The topic/subject/channel this message was received on</p>
80+
<p>The topic/subject/channel this message was received on, if any</p>
8181
<h5>Params</h5>
8282
<ul>
8383
<li><a id="method_message_topic.self"></a><code>self</code>: borrow&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
8484
</ul>
8585
<h5>Return values</h5>
8686
<ul>
87-
<li><a id="method_message_topic.0"></a> <a href="#topic"><a href="#topic"><code>topic</code></a></a></li>
87+
<li><a id="method_message_topic.0"></a> option&lt;<a href="#topic"><a href="#topic"><code>topic</code></a></a>&gt;</li>
8888
</ul>
8989
<h4><a id="method_message_content_type"></a><code>[method]message.content-type: func</code></h4>
9090
<p>An optional content-type describing the format of the data in the message. This is

messaging-request-reply.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ handling incoming messages with request/reply capabilities.</p>
7979
<li><a id="constructor_message.0"></a> own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
8080
</ul>
8181
<h4><a id="method_message_topic"></a><code>[method]message.topic: func</code></h4>
82-
<p>The topic/subject/channel this message was received on</p>
82+
<p>The topic/subject/channel this message was received on, if any</p>
8383
<h5>Params</h5>
8484
<ul>
8585
<li><a id="method_message_topic.self"></a><code>self</code>: borrow&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
8686
</ul>
8787
<h5>Return values</h5>
8888
<ul>
89-
<li><a id="method_message_topic.0"></a> <a href="#topic"><a href="#topic"><code>topic</code></a></a></li>
89+
<li><a id="method_message_topic.0"></a> option&lt;<a href="#topic"><a href="#topic"><code>topic</code></a></a>&gt;</li>
9090
</ul>
9191
<h4><a id="method_message_content_type"></a><code>[method]message.content-type: func</code></h4>
9292
<p>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.</p>
174174
#### <a id="error"></a>`type error`
175175
[`error`](#error)
176176
<p>
177+
#### <a id="topic"></a>`type topic`
178+
[`topic`](#topic)
179+
<p>
177180
#### <a id="request_options"></a>`resource request-options`
178181
<h2>Options for a request/reply operation. This is a resource to allow for future expansion of
179182
options.</h2>
@@ -214,6 +217,7 @@ return the list of messages received up to that point.</p>
214217
<h5>Params</h5>
215218
<ul>
216219
<li><a id="request.c"></a><code>c</code>: borrow&lt;<a href="#client"><a href="#client"><code>client</code></a></a>&gt;</li>
220+
<li><a id="request.topic"></a><a href="#topic"><code>topic</code></a>: <a href="#topic"><a href="#topic"><code>topic</code></a></a></li>
217221
<li><a id="request.message"></a><a href="#message"><code>message</code></a>: borrow&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
218222
<li><a id="request.options"></a><code>options</code>: option&lt;own&lt;<a href="#request_options"><a href="#request_options"><code>request-options</code></a></a>&gt;&gt;</li>
219223
</ul>

wit/request-reply.wit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// request/reply. However, request/reply is a very common pattern in messaging and as such, we have
44
/// included it as a core interface.
55
interface request-reply {
6-
use types.{client, message, error};
6+
use types.{client, message, error, topic};
77

88
/// Options for a request/reply operation. This is a resource to allow for future expansion of
99
/// options.
@@ -31,7 +31,7 @@ interface request-reply {
3131
/// error, (2) if the maximum expected number of replies were received before timeout, return
3232
/// the list of messages, or (3) if the timeout is reached before the expected number of replies,
3333
/// return the list of messages received up to that point.
34-
request: func(c: borrow<client>, message: borrow<message>, options: option<request-options>) -> result<list<message>, error>;
34+
request: func(c: borrow<client>, topic: topic, message: borrow<message>, options: option<request-options>) -> result<list<message>, error>;
3535

3636
/// Replies to the given message with the given response message. The details of which topic
3737
/// the message is sent to is up to the implementation. This allows for reply-to details to be

wit/types.wit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ interface types {
2626
/// A message with a binary payload and additional information
2727
resource message {
2828
constructor(data: list<u8>);
29-
/// The topic/subject/channel this message was received on
30-
topic: func() -> topic;
29+
/// The topic/subject/channel this message was received on, if any
30+
topic: func() -> option<topic>;
3131
/// An optional content-type describing the format of the data in the message. This is
3232
/// sometimes described as the "format" type
3333
content-type: func() -> option<string>;

0 commit comments

Comments
 (0)