├── wit ├── producer.wit ├── guest.wit ├── messaging.wit ├── types.wit └── request-reply.wit ├── .github └── workflows │ └── main.yml ├── README.md ├── messaging.md ├── imports.md ├── messaging-core.md ├── imports-request-reply.md └── messaging-request-reply.md /wit/producer.wit: -------------------------------------------------------------------------------- 1 | /// The producer interface is used to send messages to a channel/topic. 2 | interface producer { 3 | use types.{client, message, error, topic}; 4 | 5 | /// Sends the message using the given client. 6 | send: func(c: borrow, topic: topic, message: message) -> result<_, error>; 7 | } 8 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: [main] 5 | pull_request: 6 | branches: [main] 7 | 8 | jobs: 9 | abi-up-to-date: 10 | name: Check ABI files are up-to-date 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - uses: WebAssembly/wit-abi-up-to-date@v17 15 | with: 16 | wit-bindgen: '0.34.0' 17 | worlds: 'imports imports-request-reply messaging-core messaging-request-reply' 18 | -------------------------------------------------------------------------------- /wit/guest.wit: -------------------------------------------------------------------------------- 1 | interface incoming-handler { 2 | use types.{message, error, topic}; 3 | 4 | /// Whenever this guest receives a message in one of the subscribed topics, the message is 5 | /// sent to this handler. The guest is responsible for matching on the topic and handling the 6 | /// message accordingly. Implementors (such as hosts) calling this interface should make their 7 | /// own decisions on how to handle errors returned from this function. 8 | handle: func(message: message) -> result<_, error>; 9 | } 10 | -------------------------------------------------------------------------------- /wit/messaging.wit: -------------------------------------------------------------------------------- 1 | package wasi:messaging@0.2.0-draft; 2 | 3 | /// The `imports` world defines the interfaces that the component will import from the host. 4 | /// It includes the `producer` interface for sending messages. 5 | world imports { 6 | import producer; 7 | } 8 | 9 | /// The `imports-request-reply` world extends `imports` by including the `request-reply` interface. 10 | /// This allows the component to perform request/reply messaging patterns. 11 | world imports-request-reply { 12 | include imports; 13 | import request-reply; 14 | } 15 | 16 | /// The `messaging-request-reply` world combines `imports-request-reply` with the `incoming-handler` 17 | /// export. This setup allows the host to interact with the component for both sending messages and 18 | /// handling incoming messages with request/reply capabilities. 19 | world messaging-request-reply { 20 | include imports-request-reply; 21 | export incoming-handler; 22 | } 23 | 24 | /// The `messaging-core` world includes the basic `imports` and exports the `incoming-handler`, 25 | /// enabling the component to handle incoming messages without request/reply capabilities. 26 | world messaging-core { 27 | include imports; 28 | export incoming-handler; 29 | } 30 | -------------------------------------------------------------------------------- /wit/types.wit: -------------------------------------------------------------------------------- 1 | interface types { 2 | /// A type alias for list> to represent metadata attached to a message 3 | type metadata = list>; 4 | 5 | /// A type alias for string to represent a message topic 6 | type topic = string; 7 | 8 | /// A connection to a message-exchange service (e.g., buffer, broker, etc.). 9 | resource client { 10 | connect: static func(name: string) -> result; 11 | disconnect: func() -> result<_, error>; 12 | } 13 | 14 | /// Errors that can occur when using the messaging interface. 15 | variant error { 16 | /// The request or operation timed out. 17 | timeout, 18 | /// An error occurred with the connection. Includes a message for additional context 19 | connection(string), 20 | /// A permission error occurred. Includes a message for additional context 21 | permission-denied(string), 22 | /// A catch all for other types of errors 23 | other(string), 24 | } 25 | 26 | /// A message with a binary payload and additional information 27 | resource message { 28 | constructor(data: list); 29 | /// The topic/subject/channel this message was received on, if any 30 | topic: func() -> option; 31 | /// An optional content-type describing the format of the data in the message. This is 32 | /// sometimes described as the "format" type 33 | content-type: func() -> option; 34 | /// Set the content-type describing the format of the data in the message. This is 35 | /// sometimes described as the "format" type 36 | set-content-type: func(content-type: string); 37 | /// An opaque blob of data 38 | data: func() -> list; 39 | /// Set the opaque blob of data for this message, discarding the old value 40 | set-data: func(data: list); 41 | /// Optional metadata (also called headers or attributes in some systems) attached to the 42 | /// message. This metadata is simply decoration and should not be interpreted by a host 43 | /// to ensure portability across different implementors (e.g., Kafka -> NATS, etc.). 44 | metadata: func() -> option; 45 | /// Add a new key-value pair to the metadata, overwriting any existing value for the same key 46 | add-metadata: func(key: string, value: string); 47 | /// Set the metadata 48 | set-metadata: func(meta: metadata); 49 | /// Remove a key-value pair from the metadata 50 | remove-metadata: func(key: string); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /wit/request-reply.wit: -------------------------------------------------------------------------------- 1 | /// The request-reply interface allows a guest to send a message and await a response. This 2 | /// interface is considered optional as not all message services support the concept of 3 | /// request/reply. However, request/reply is a very common pattern in messaging and as such, we have 4 | /// included it as a core interface. 5 | interface request-reply { 6 | use types.{client, message, error, topic}; 7 | 8 | /// Options for a request/reply operation. This is a resource to allow for future expansion of 9 | /// options. 10 | resource request-options { 11 | /// Creates a new request options resource with no options set. 12 | constructor(); 13 | 14 | /// The maximum amount of time to wait for a response. If the timeout value is not set, then 15 | /// the request/reply operation will block until a message is received in response. 16 | set-timeout-ms: func(timeout-ms: u32); 17 | 18 | /// The maximum number of replies to expect before returning. 19 | set-expected-replies: func(expected-replies: u32); 20 | } 21 | 22 | /// Performs a blocking request/reply operation with an optional set of request options. 23 | /// 24 | /// The behavior of this function is largely dependent on the options given to the function. 25 | /// If no options are provided, then the request/reply operation will block until a single 26 | /// message is received in response. If a timeout is provided, then the request/reply operation 27 | /// will block for the specified amount of time before returning an error if no messages were 28 | /// received (or the list of messages that were received). If both a timeout and an expected 29 | /// number of replies are provided, the function should return when either condition is met 30 | /// (whichever comes first)—e.g., (1) if no replies were received within the timeout return an 31 | /// error, (2) if the maximum expected number of replies were received before timeout, return 32 | /// the list of messages, or (3) if the timeout is reached before the expected number of replies, 33 | /// return the list of messages received up to that point. 34 | request: func(c: borrow, topic: topic, message: borrow, options: option) -> result, error>; 35 | 36 | /// Replies to the given message with the given response message. The details of which topic 37 | /// the message is sent to is up to the implementation. This allows for reply-to details to be 38 | /// handled in the best way possible for the underlying messaging system. 39 | /// 40 | /// Please note that this reply functionality is different than something like HTTP because there 41 | /// are several use cases in which a reply might not be required for every message (so this would 42 | /// be a noop). There are also cases when you might want to reply and then continue processing. 43 | /// Additionally, you might want to reply to a message several times (such as providing an 44 | /// update). So this function is allowed to be called multiple times, unlike something like HTTP 45 | /// where the reply is sent and the connection is closed. 46 | reply: func(reply-to: borrow, message: message) -> result<_, error>; 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `wasi-messaging` 2 | 3 | A proposed [WebAssembly System Interface](https://github.com/WebAssembly/WASI) API. 4 | 5 | ## Table of Contents 6 | 7 | - [`wasi-messaging`](#wasi-messaging) 8 | - [Table of Contents](#table-of-contents) 9 | - [Current Phase](#current-phase) 10 | - [Champions](#champions) 11 | - [Phase 4 Advancement Criteria](#phase-4-advancement-criteria) 12 | - [Introduction](#introduction) 13 | - [Goals](#goals) 14 | - [Portability criteria](#portability-criteria) 15 | - [Dev notes](#dev-notes) 16 | 17 | ## Current Phase 18 | 19 | `wasi-messaging` is currently in [Phase 20 | 1](https://github.com/WebAssembly/WASI/blob/main/Proposals.md#phase-1---feature-proposal-cg). 21 | 22 | ## Champions 23 | 24 | - [Dan Chiarlone](https://github.com/danbugs) 25 | - [David Justice](https://github.com/devigned) 26 | - [Jiaxiao Zhou](https://github.com/Mossaka) 27 | 28 | ## Phase 4 Advancement Criteria 29 | 30 | For `wasi-messaging` to advance to Phase 4, it must have at least two independent implementations 31 | for open-source message brokers (such as Kafka, NATS, MQTT brokers) and two for cloud service providers 32 | (e.g., Azure Service Bus, AWS SQS). 33 | 34 | ## Introduction 35 | 36 | In modern software systems, different components or applications often need to communicate with each other 37 | to exchange information and coordinate their actions. Messaging systems facilitate this communication by 38 | allowing messages to be sent and received between different parts of a system. 39 | 40 | However, implementing message-based communication can be challenging. It requires dealing with the details 41 | of message brokers, such as connection management, channel setup, and message serialization. This complexity 42 | can hinder development and lead to inconsistent implementations. 43 | 44 | The `wasi-messaging` interface is a purposefully small interface focused purely on message passing. It is 45 | designed to express the bare minimum of receiving a message and sending a message, along with an optional 46 | request/reply interface that allows for message-based APIs and/or RPC. 47 | 48 | By providing a standard way to interact with message brokers, the `wasi-messaging` interface aims to simplify 49 | this process, hiding the underlying complexity from the user. This aligns with the broader goals of WASI by 50 | promoting interoperability, modularity, and security in WebAssembly applications. 51 | 52 | ## Goals 53 | 54 | The primary goal of this interface is to focus on message passing. The only guarantee offered is 55 | that publishing a message is handled successfully. No other guarantees are made about the delivery 56 | of the message or being able to ack/nack a message directly. This minimalist approach provides the 57 | most basic foundation of messaging, which can be expanded upon by future interfaces or proposals as 58 | use cases emerge. 59 | 60 | This simplicity allows: 61 | - **Ease of Integration**: Components can easily implement the message handler in this interface, 62 | with details such as work dispatch and queuing handled behind the scenes, invisible to the business logic. 63 | - **Flexibility**: Anything that can send a message can easily be passed into a queue 64 | (such as a Kafka stream or NATS JetStream) without the knowledge that it is being sent into a queue. 65 | - **Extensibility**: The paradigm can be expanded by future interfaces (like a queue-based work interface) to handle 66 | more complex messaging scenarios. By focusing solely on message passing, the wasi-messaging interface simplifies the 67 | development of interoperable WebAssembly modules that can communicate over various messaging systems without being 68 | tied to any specific implementation. 69 | 70 | ## Portability criteria 71 | 72 | The main portability criteria on which this should be judged is whether a component can receive and send a message 73 | from all major messaging systems. This includes: 74 | - Message standards like MQTT and AMQP. 75 | - Specific technologies like NATS and Kafka. 76 | - Cloud provider implementations like Azure Service Bus and AWS SQS. 77 | 78 | This _does not_ mean it implements the full set of features of each of the messaging systems. In fact, it is expected 79 | that most implementations will need to do work to adapt their system to this interface (e.g., in Kafka, you'd have 80 | to mark the message as completed once the call to handle returns). 81 | 82 | As mentioned above, this should still be completely compatible with any more advanced use cases of the various 83 | message systems. For example, if you have a queue of work that is currently being handled by pre-existing software 84 | outside of Wasm components, a component could use this interface to publish messages that get ingested into this queue. 85 | 86 | Another way to state the portability criteria is that this implementation should not break the possibility of a 87 | component consuming this interface to be integrated with a more advanced messaging use case. 88 | 89 | ## Dev notes 90 | 91 | To regenerate the `.md` files, run: 92 | ```sh 93 | wit-bindgen markdown ./wit/ -w imports --html-in-md 94 | wit-bindgen markdown ./wit/ -w imports-request-reply --html-in-md 95 | wit-bindgen markdown ./wit/ -w messaging-core --html-in-md 96 | wit-bindgen markdown ./wit/ -w messaging-request-reply --html-in-md 97 | ``` 98 | 99 | It would make sense for a lot of these functions to be asynchronous, but that is not currently natively supported in 100 | the component model. Asynchronous support will be added as part of WASI Preview 3. When async support becomes 101 | available, we plan to update the wasi-messaging interface to incorporate asynchronous patterns. 102 | 103 | > **Note**: Ensure you have version 0.34.0 of `wit-bindgen` installed to avoid compatibility issues. 104 | -------------------------------------------------------------------------------- /messaging.md: -------------------------------------------------------------------------------- 1 |

World messaging

2 | 15 |

Import interface wasi:messaging/types@0.2.0-draft

16 |
17 |

Types

18 |

resource client

19 |

A connection to a message-exchange service (e.g., buffer, broker, etc.).

20 |

variant error

21 |

Errors that can occur when using the messaging interface.

22 |
Variant Cases
23 |
    24 |
  • 25 |

    timeout

    26 |

    The request or operation timed out. 27 |

  • 28 |
  • 29 |

    connection: string

    30 |

    An error occurred with the connection. Includes a message for additional context 31 |

  • 32 |
  • 33 |

    other: string

    34 |

    A catch all for other types of errors 35 |

  • 36 |
37 |

resource message

38 |

A message with a binary payload and additional information

39 |

Functions

40 |

[static]client.connect: func

41 |
Params
42 |
    43 |
  • name: string
  • 44 |
45 |
Return values
46 | 49 |

[constructor]message: func

50 |
Params
51 |
    52 |
  • topic: string
  • 53 |
  • data: list<u8>
  • 54 |
55 |
Return values
56 | 59 |

[method]message.topic: func

60 |

The topic/subject/channel this message was received or should be sent on

61 |
Params
62 | 65 |
Return values
66 |
    67 |
  • string
  • 68 |
69 |

[method]message.set-topic: func

70 |

Set the topic/subject/channel this message should be sent on

71 |
Params
72 |
    73 |
  • self: borrow<message>
  • 74 |
  • topic: string
  • 75 |
76 |

[method]message.content-type: func

77 |

An optional content-type describing the format of the data in the message. This is 78 | sometimes described as the "format" type

79 |
Params
80 | 83 |
Return values
84 |
    85 |
  • option<string>
  • 86 |
87 |

[method]message.set-content-type: func

88 |

Set the content-type describing the format of the data in the message. This is 89 | sometimes described as the "format" type

90 |
Params
91 |
    92 |
  • self: borrow<message>
  • 93 |
  • content-type: string
  • 94 |
95 |

[method]message.data: func

96 |

An opaque blob of data

97 |
Params
98 | 101 |
Return values
102 |
    103 |
  • list<u8>
  • 104 |
105 |

[method]message.set-data: func

106 |

Set the opaque blob of data for this message, discarding the old value

107 |
Params
108 |
    109 |
  • self: borrow<message>
  • 110 |
  • data: list<u8>
  • 111 |
112 |

[method]message.metadata: func

113 |

Optional metadata (also called headers or attributes in some systems) attached to the 114 | message

115 |
Params
116 |
    117 |
  • self: borrow<message>
  • 118 |
119 |
Return values
120 |
    121 |
  • option<list<(string, string)>>
  • 122 |
123 |

[method]message.add-metadata: func

124 |

Add a new key-value pair to the metadata, overwriting any existing value for the same key

125 |
Params
126 |
    127 |
  • self: borrow<message>
  • 128 |
  • key: string
  • 129 |
  • value: string
  • 130 |
131 |

Import interface wasi:messaging/producer@0.2.0-draft

132 |

The producer interface is used to send messages to a channel/topic.

133 |
134 |

Types

135 |

type client

136 |

client

137 |

138 | #### `type message` 139 | [`message`](#message) 140 |

141 | #### `type error` 142 | [`error`](#error) 143 |

144 | ---- 145 |

Functions

146 |

send: func

147 |

Sends the message using the given client.

148 |
Params
149 | 153 |
Return values
154 |
    155 |
  • result<_, error>
  • 156 |
157 |

Export interface wasi:messaging/incoming-handler@0.2.0-draft

158 |
159 |

Types

160 |

type message

161 |

message

162 |

163 | #### `type error` 164 | [`error`](#error) 165 |

166 | ---- 167 |

Functions

168 |

handle: func

169 |

Whenever this guest receives a message in one of the subscribed channels, the message is 170 | sent to this handler. The guest is responsible for matching on the channel and handling the 171 | message accordingly. Implementors (such as hosts) calling this interface should make their 172 | own decisions on how to handle errors returned from this function.

173 |
Params
174 | 177 |
Return values
178 |
    179 |
  • result<_, error>
  • 180 |
181 |

subscribe: func

182 |

Subscribe to a list of topics (represented as strings) at runtime. 183 | Implementors should consider also allowing subscriptions to be made at compile time via 184 | some sort of configuration file.

185 |
Return values
186 |
    187 |
  • result<list<string>, error>
  • 188 |
189 | -------------------------------------------------------------------------------- /imports.md: -------------------------------------------------------------------------------- 1 |

World imports

2 |

The imports world defines the interfaces that the component will import from the host. 3 | It includes the producer interface for sending messages.

4 | 12 |

Import interface wasi:messaging/types@0.2.0-draft

13 |
14 |

Types

15 |

type metadata

16 |

metadata

17 |

A type alias for list> to represent metadata attached to a message 18 |

type topic

19 |

string

20 |

A type alias for string to represent a message topic 21 |

resource client

22 |

A connection to a message-exchange service (e.g., buffer, broker, etc.).

23 |

variant error

24 |

Errors that can occur when using the messaging interface.

25 |
Variant Cases
26 |
    27 |
  • 28 |

    timeout

    29 |

    The request or operation timed out. 30 |

  • 31 |
  • 32 |

    connection: string

    33 |

    An error occurred with the connection. Includes a message for additional context 34 |

  • 35 |
  • 36 |

    permission-denied: string

    37 |

    A permission error occurred. Includes a message for additional context 38 |

  • 39 |
  • 40 |

    other: string

    41 |

    A catch all for other types of errors 42 |

  • 43 |
44 |

resource message

45 |

A message with a binary payload and additional information

46 |

Functions

47 |

[static]client.connect: func

48 |
Params
49 |
    50 |
  • name: string
  • 51 |
52 |
Return values
53 | 56 |

[method]client.disconnect: func

57 |
Params
58 |
    59 |
  • self: borrow<client>
  • 60 |
61 |
Return values
62 |
    63 |
  • result<_, error>
  • 64 |
65 |

[constructor]message: func

66 |
Params
67 |
    68 |
  • data: list<u8>
  • 69 |
70 |
Return values
71 | 74 |

[method]message.topic: func

75 |

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

76 |
Params
77 | 80 |
Return values
81 |
    82 |
  • option<topic>
  • 83 |
84 |

[method]message.content-type: func

85 |

An optional content-type describing the format of the data in the message. This is 86 | sometimes described as the "format" type

87 |
Params
88 | 91 |
Return values
92 |
    93 |
  • option<string>
  • 94 |
95 |

[method]message.set-content-type: func

96 |

Set the content-type describing the format of the data in the message. This is 97 | sometimes described as the "format" type

98 |
Params
99 |
    100 |
  • self: borrow<message>
  • 101 |
  • content-type: string
  • 102 |
103 |

[method]message.data: func

104 |

An opaque blob of data

105 |
Params
106 |
    107 |
  • self: borrow<message>
  • 108 |
109 |
Return values
110 |
    111 |
  • list<u8>
  • 112 |
113 |

[method]message.set-data: func

114 |

Set the opaque blob of data for this message, discarding the old value

115 |
Params
116 |
    117 |
  • self: borrow<message>
  • 118 |
  • data: list<u8>
  • 119 |
120 |

[method]message.metadata: func

121 |

Optional metadata (also called headers or attributes in some systems) attached to the 122 | message. This metadata is simply decoration and should not be interpreted by a host 123 | to ensure portability across different implementors (e.g., Kafka -> NATS, etc.).

124 |
Params
125 |
    126 |
  • self: borrow<message>
  • 127 |
128 |
Return values
129 | 132 |

[method]message.add-metadata: func

133 |

Add a new key-value pair to the metadata, overwriting any existing value for the same key

134 |
Params
135 |
    136 |
  • self: borrow<message>
  • 137 |
  • key: string
  • 138 |
  • value: string
  • 139 |
140 |

[method]message.set-metadata: func

141 |

Set the metadata

142 |
Params
143 | 147 |

[method]message.remove-metadata: func

148 |

Remove a key-value pair from the metadata

149 |
Params
150 |
    151 |
  • self: borrow<message>
  • 152 |
  • key: string
  • 153 |
154 |

Import interface wasi:messaging/producer@0.2.0-draft

155 |

The producer interface is used to send messages to a channel/topic.

156 |
157 |

Types

158 |

type client

159 |

client

160 |

161 | #### `type message` 162 | [`message`](#message) 163 |

164 | #### `type error` 165 | [`error`](#error) 166 |

167 | #### `type topic` 168 | [`topic`](#topic) 169 |

170 | ---- 171 |

Functions

172 |

send: func

173 |

Sends the message using the given client.

174 |
Params
175 | 180 |
Return values
181 |
    182 |
  • result<_, error>
  • 183 |
184 | -------------------------------------------------------------------------------- /messaging-core.md: -------------------------------------------------------------------------------- 1 |

World messaging-core

2 |

The messaging-core world includes the basic imports and exports the incoming-handler, 3 | enabling the component to handle incoming messages without request/reply capabilities.

4 | 17 |

Import interface wasi:messaging/types@0.2.0-draft

18 |
19 |

Types

20 |

type metadata

21 |

metadata

22 |

A type alias for list> to represent metadata attached to a message 23 |

type topic

24 |

string

25 |

A type alias for string to represent a message topic 26 |

resource client

27 |

A connection to a message-exchange service (e.g., buffer, broker, etc.).

28 |

variant error

29 |

Errors that can occur when using the messaging interface.

30 |
Variant Cases
31 |
    32 |
  • 33 |

    timeout

    34 |

    The request or operation timed out. 35 |

  • 36 |
  • 37 |

    connection: string

    38 |

    An error occurred with the connection. Includes a message for additional context 39 |

  • 40 |
  • 41 |

    permission-denied: string

    42 |

    A permission error occurred. Includes a message for additional context 43 |

  • 44 |
  • 45 |

    other: string

    46 |

    A catch all for other types of errors 47 |

  • 48 |
49 |

resource message

50 |

A message with a binary payload and additional information

51 |

Functions

52 |

[static]client.connect: func

53 |
Params
54 |
    55 |
  • name: string
  • 56 |
57 |
Return values
58 | 61 |

[method]client.disconnect: func

62 |
Params
63 |
    64 |
  • self: borrow<client>
  • 65 |
66 |
Return values
67 |
    68 |
  • result<_, error>
  • 69 |
70 |

[constructor]message: func

71 |
Params
72 |
    73 |
  • data: list<u8>
  • 74 |
75 |
Return values
76 | 79 |

[method]message.topic: func

80 |

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

81 |
Params
82 | 85 |
Return values
86 |
    87 |
  • option<topic>
  • 88 |
89 |

[method]message.content-type: func

90 |

An optional content-type describing the format of the data in the message. This is 91 | sometimes described as the "format" type

92 |
Params
93 | 96 |
Return values
97 |
    98 |
  • option<string>
  • 99 |
100 |

[method]message.set-content-type: func

101 |

Set the content-type describing the format of the data in the message. This is 102 | sometimes described as the "format" type

103 |
Params
104 |
    105 |
  • self: borrow<message>
  • 106 |
  • content-type: string
  • 107 |
108 |

[method]message.data: func

109 |

An opaque blob of data

110 |
Params
111 |
    112 |
  • self: borrow<message>
  • 113 |
114 |
Return values
115 |
    116 |
  • list<u8>
  • 117 |
118 |

[method]message.set-data: func

119 |

Set the opaque blob of data for this message, discarding the old value

120 |
Params
121 |
    122 |
  • self: borrow<message>
  • 123 |
  • data: list<u8>
  • 124 |
125 |

[method]message.metadata: func

126 |

Optional metadata (also called headers or attributes in some systems) attached to the 127 | message. This metadata is simply decoration and should not be interpreted by a host 128 | to ensure portability across different implementors (e.g., Kafka -> NATS, etc.).

129 |
Params
130 |
    131 |
  • self: borrow<message>
  • 132 |
133 |
Return values
134 | 137 |

[method]message.add-metadata: func

138 |

Add a new key-value pair to the metadata, overwriting any existing value for the same key

139 |
Params
140 |
    141 |
  • self: borrow<message>
  • 142 |
  • key: string
  • 143 |
  • value: string
  • 144 |
145 |

[method]message.set-metadata: func

146 |

Set the metadata

147 |
Params
148 | 152 |

[method]message.remove-metadata: func

153 |

Remove a key-value pair from the metadata

154 |
Params
155 |
    156 |
  • self: borrow<message>
  • 157 |
  • key: string
  • 158 |
159 |

Import interface wasi:messaging/producer@0.2.0-draft

160 |

The producer interface is used to send messages to a channel/topic.

161 |
162 |

Types

163 |

type client

164 |

client

165 |

166 | #### `type message` 167 | [`message`](#message) 168 |

169 | #### `type error` 170 | [`error`](#error) 171 |

172 | #### `type topic` 173 | [`topic`](#topic) 174 |

175 | ---- 176 |

Functions

177 |

send: func

178 |

Sends the message using the given client.

179 |
Params
180 | 185 |
Return values
186 |
    187 |
  • result<_, error>
  • 188 |
189 |

Export interface wasi:messaging/incoming-handler@0.2.0-draft

190 |
191 |

Types

192 |

type message

193 |

message

194 |

195 | #### `type error` 196 | [`error`](#error) 197 |

198 | #### `type topic` 199 | [`topic`](#topic) 200 |

201 | ---- 202 |

Functions

203 |

handle: func

204 |

Whenever this guest receives a message in one of the subscribed topics, the message is 205 | sent to this handler. The guest is responsible for matching on the topic and handling the 206 | message accordingly. Implementors (such as hosts) calling this interface should make their 207 | own decisions on how to handle errors returned from this function.

208 |
Params
209 | 212 |
Return values
213 |
    214 |
  • result<_, error>
  • 215 |
216 | -------------------------------------------------------------------------------- /imports-request-reply.md: -------------------------------------------------------------------------------- 1 |

World imports-request-reply

2 |

The imports-request-reply world extends imports by including the request-reply interface. 3 | This allows the component to perform request/reply messaging patterns.

4 | 13 |

Import interface wasi:messaging/types@0.2.0-draft

14 |
15 |

Types

16 |

type metadata

17 |

metadata

18 |

A type alias for list> to represent metadata attached to a message 19 |

type topic

20 |

string

21 |

A type alias for string to represent a message topic 22 |

resource client

23 |

A connection to a message-exchange service (e.g., buffer, broker, etc.).

24 |

variant error

25 |

Errors that can occur when using the messaging interface.

26 |
Variant Cases
27 |
    28 |
  • 29 |

    timeout

    30 |

    The request or operation timed out. 31 |

  • 32 |
  • 33 |

    connection: string

    34 |

    An error occurred with the connection. Includes a message for additional context 35 |

  • 36 |
  • 37 |

    permission-denied: string

    38 |

    A permission error occurred. Includes a message for additional context 39 |

  • 40 |
  • 41 |

    other: string

    42 |

    A catch all for other types of errors 43 |

  • 44 |
45 |

resource message

46 |

A message with a binary payload and additional information

47 |

Functions

48 |

[static]client.connect: func

49 |
Params
50 |
    51 |
  • name: string
  • 52 |
53 |
Return values
54 | 57 |

[method]client.disconnect: func

58 |
Params
59 |
    60 |
  • self: borrow<client>
  • 61 |
62 |
Return values
63 |
    64 |
  • result<_, error>
  • 65 |
66 |

[constructor]message: func

67 |
Params
68 |
    69 |
  • data: list<u8>
  • 70 |
71 |
Return values
72 | 75 |

[method]message.topic: func

76 |

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

77 |
Params
78 | 81 |
Return values
82 |
    83 |
  • option<topic>
  • 84 |
85 |

[method]message.content-type: func

86 |

An optional content-type describing the format of the data in the message. This is 87 | sometimes described as the "format" type

88 |
Params
89 | 92 |
Return values
93 |
    94 |
  • option<string>
  • 95 |
96 |

[method]message.set-content-type: func

97 |

Set the content-type describing the format of the data in the message. This is 98 | sometimes described as the "format" type

99 |
Params
100 |
    101 |
  • self: borrow<message>
  • 102 |
  • content-type: string
  • 103 |
104 |

[method]message.data: func

105 |

An opaque blob of data

106 |
Params
107 |
    108 |
  • self: borrow<message>
  • 109 |
110 |
Return values
111 |
    112 |
  • list<u8>
  • 113 |
114 |

[method]message.set-data: func

115 |

Set the opaque blob of data for this message, discarding the old value

116 |
Params
117 |
    118 |
  • self: borrow<message>
  • 119 |
  • data: list<u8>
  • 120 |
121 |

[method]message.metadata: func

122 |

Optional metadata (also called headers or attributes in some systems) attached to the 123 | message. This metadata is simply decoration and should not be interpreted by a host 124 | to ensure portability across different implementors (e.g., Kafka -> NATS, etc.).

125 |
Params
126 |
    127 |
  • self: borrow<message>
  • 128 |
129 |
Return values
130 | 133 |

[method]message.add-metadata: func

134 |

Add a new key-value pair to the metadata, overwriting any existing value for the same key

135 |
Params
136 |
    137 |
  • self: borrow<message>
  • 138 |
  • key: string
  • 139 |
  • value: string
  • 140 |
141 |

[method]message.set-metadata: func

142 |

Set the metadata

143 |
Params
144 | 148 |

[method]message.remove-metadata: func

149 |

Remove a key-value pair from the metadata

150 |
Params
151 |
    152 |
  • self: borrow<message>
  • 153 |
  • key: string
  • 154 |
155 |

Import interface wasi:messaging/request-reply@0.2.0-draft

156 |

The request-reply interface allows a guest to send a message and await a response. This 157 | interface is considered optional as not all message services support the concept of 158 | request/reply. However, request/reply is a very common pattern in messaging and as such, we have 159 | included it as a core interface.

160 |
161 |

Types

162 |

type client

163 |

client

164 |

165 | #### `type message` 166 | [`message`](#message) 167 |

168 | #### `type error` 169 | [`error`](#error) 170 |

171 | #### `type topic` 172 | [`topic`](#topic) 173 |

174 | #### `resource request-options` 175 |

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

177 |

Functions

178 |

[constructor]request-options: func

179 |

Creates a new request options resource with no options set.

180 |
Return values
181 | 184 |

[method]request-options.set-timeout-ms: func

185 |

The maximum amount of time to wait for a response. If the timeout value is not set, then 186 | the request/reply operation will block until a message is received in response.

187 |
Params
188 | 192 |

[method]request-options.set-expected-replies: func

193 |

The maximum number of replies to expect before returning.

194 |
Params
195 | 199 |

request: func

200 |

Performs a blocking request/reply operation with an optional set of request options.

201 |

The behavior of this function is largely dependent on the options given to the function. 202 | If no options are provided, then the request/reply operation will block until a single 203 | message is received in response. If a timeout is provided, then the request/reply operation 204 | will block for the specified amount of time before returning an error if no messages were 205 | received (or the list of messages that were received). If both a timeout and an expected 206 | number of replies are provided, the function should return when either condition is met 207 | (whichever comes first)—e.g., (1) if no replies were received within the timeout return an 208 | error, (2) if the maximum expected number of replies were received before timeout, return 209 | the list of messages, or (3) if the timeout is reached before the expected number of replies, 210 | return the list of messages received up to that point.

211 |
Params
212 | 218 |
Return values
219 | 222 |

reply: func

223 |

Replies to the given message with the given response message. The details of which topic 224 | the message is sent to is up to the implementation. This allows for reply-to details to be 225 | handled in the best way possible for the underlying messaging system.

226 |

Please note that this reply functionality is different than something like HTTP because there 227 | are several use cases in which a reply might not be required for every message (so this would 228 | be a noop). There are also cases when you might want to reply and then continue processing. 229 | Additionally, you might want to reply to a message several times (such as providing an 230 | update). So this function is allowed to be called multiple times, unlike something like HTTP 231 | where the reply is sent and the connection is closed.

232 |
Params
233 | 237 |
Return values
238 |
    239 |
  • result<_, error>
  • 240 |
241 |

Import interface wasi:messaging/producer@0.2.0-draft

242 |

The producer interface is used to send messages to a channel/topic.

243 |
244 |

Types

245 |

type client

246 |

client

247 |

248 | #### `type message` 249 | [`message`](#message) 250 |

251 | #### `type error` 252 | [`error`](#error) 253 |

254 | #### `type topic` 255 | [`topic`](#topic) 256 |

257 | ---- 258 |

Functions

259 |

send: func

260 |

Sends the message using the given client.

261 |
Params
262 | 267 |
Return values
268 |
    269 |
  • result<_, error>
  • 270 |
271 | -------------------------------------------------------------------------------- /messaging-request-reply.md: -------------------------------------------------------------------------------- 1 |

World messaging-request-reply

2 |

The messaging-request-reply world combines imports-request-reply with the incoming-handler 3 | export. This setup allows the host to interact with the component for both sending messages and 4 | handling incoming messages with request/reply capabilities.

5 | 19 |

Import interface wasi:messaging/types@0.2.0-draft

20 |
21 |

Types

22 |

type metadata

23 |

metadata

24 |

A type alias for list> to represent metadata attached to a message 25 |

type topic

26 |

string

27 |

A type alias for string to represent a message topic 28 |

resource client

29 |

A connection to a message-exchange service (e.g., buffer, broker, etc.).

30 |

variant error

31 |

Errors that can occur when using the messaging interface.

32 |
Variant Cases
33 |
    34 |
  • 35 |

    timeout

    36 |

    The request or operation timed out. 37 |

  • 38 |
  • 39 |

    connection: string

    40 |

    An error occurred with the connection. Includes a message for additional context 41 |

  • 42 |
  • 43 |

    permission-denied: string

    44 |

    A permission error occurred. Includes a message for additional context 45 |

  • 46 |
  • 47 |

    other: string

    48 |

    A catch all for other types of errors 49 |

  • 50 |
51 |

resource message

52 |

A message with a binary payload and additional information

53 |

Functions

54 |

[static]client.connect: func

55 |
Params
56 |
    57 |
  • name: string
  • 58 |
59 |
Return values
60 | 63 |

[method]client.disconnect: func

64 |
Params
65 |
    66 |
  • self: borrow<client>
  • 67 |
68 |
Return values
69 |
    70 |
  • result<_, error>
  • 71 |
72 |

[constructor]message: func

73 |
Params
74 |
    75 |
  • data: list<u8>
  • 76 |
77 |
Return values
78 | 81 |

[method]message.topic: func

82 |

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

83 |
Params
84 | 87 |
Return values
88 |
    89 |
  • option<topic>
  • 90 |
91 |

[method]message.content-type: func

92 |

An optional content-type describing the format of the data in the message. This is 93 | sometimes described as the "format" type

94 |
Params
95 | 98 |
Return values
99 |
    100 |
  • option<string>
  • 101 |
102 |

[method]message.set-content-type: func

103 |

Set the content-type describing the format of the data in the message. This is 104 | sometimes described as the "format" type

105 |
Params
106 |
    107 |
  • self: borrow<message>
  • 108 |
  • content-type: string
  • 109 |
110 |

[method]message.data: func

111 |

An opaque blob of data

112 |
Params
113 |
    114 |
  • self: borrow<message>
  • 115 |
116 |
Return values
117 |
    118 |
  • list<u8>
  • 119 |
120 |

[method]message.set-data: func

121 |

Set the opaque blob of data for this message, discarding the old value

122 |
Params
123 |
    124 |
  • self: borrow<message>
  • 125 |
  • data: list<u8>
  • 126 |
127 |

[method]message.metadata: func

128 |

Optional metadata (also called headers or attributes in some systems) attached to the 129 | message. This metadata is simply decoration and should not be interpreted by a host 130 | to ensure portability across different implementors (e.g., Kafka -> NATS, etc.).

131 |
Params
132 |
    133 |
  • self: borrow<message>
  • 134 |
135 |
Return values
136 | 139 |

[method]message.add-metadata: func

140 |

Add a new key-value pair to the metadata, overwriting any existing value for the same key

141 |
Params
142 |
    143 |
  • self: borrow<message>
  • 144 |
  • key: string
  • 145 |
  • value: string
  • 146 |
147 |

[method]message.set-metadata: func

148 |

Set the metadata

149 |
Params
150 | 154 |

[method]message.remove-metadata: func

155 |

Remove a key-value pair from the metadata

156 |
Params
157 |
    158 |
  • self: borrow<message>
  • 159 |
  • key: string
  • 160 |
161 |

Import interface wasi:messaging/request-reply@0.2.0-draft

162 |

The request-reply interface allows a guest to send a message and await a response. This 163 | interface is considered optional as not all message services support the concept of 164 | request/reply. However, request/reply is a very common pattern in messaging and as such, we have 165 | included it as a core interface.

166 |
167 |

Types

168 |

type client

169 |

client

170 |

171 | #### `type message` 172 | [`message`](#message) 173 |

174 | #### `type error` 175 | [`error`](#error) 176 |

177 | #### `type topic` 178 | [`topic`](#topic) 179 |

180 | #### `resource request-options` 181 |

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

183 |

Functions

184 |

[constructor]request-options: func

185 |

Creates a new request options resource with no options set.

186 |
Return values
187 | 190 |

[method]request-options.set-timeout-ms: func

191 |

The maximum amount of time to wait for a response. If the timeout value is not set, then 192 | the request/reply operation will block until a message is received in response.

193 |
Params
194 | 198 |

[method]request-options.set-expected-replies: func

199 |

The maximum number of replies to expect before returning.

200 |
Params
201 | 205 |

request: func

206 |

Performs a blocking request/reply operation with an optional set of request options.

207 |

The behavior of this function is largely dependent on the options given to the function. 208 | If no options are provided, then the request/reply operation will block until a single 209 | message is received in response. If a timeout is provided, then the request/reply operation 210 | will block for the specified amount of time before returning an error if no messages were 211 | received (or the list of messages that were received). If both a timeout and an expected 212 | number of replies are provided, the function should return when either condition is met 213 | (whichever comes first)—e.g., (1) if no replies were received within the timeout return an 214 | error, (2) if the maximum expected number of replies were received before timeout, return 215 | the list of messages, or (3) if the timeout is reached before the expected number of replies, 216 | return the list of messages received up to that point.

217 |
Params
218 | 224 |
Return values
225 | 228 |

reply: func

229 |

Replies to the given message with the given response message. The details of which topic 230 | the message is sent to is up to the implementation. This allows for reply-to details to be 231 | handled in the best way possible for the underlying messaging system.

232 |

Please note that this reply functionality is different than something like HTTP because there 233 | are several use cases in which a reply might not be required for every message (so this would 234 | be a noop). There are also cases when you might want to reply and then continue processing. 235 | Additionally, you might want to reply to a message several times (such as providing an 236 | update). So this function is allowed to be called multiple times, unlike something like HTTP 237 | where the reply is sent and the connection is closed.

238 |
Params
239 | 243 |
Return values
244 |
    245 |
  • result<_, error>
  • 246 |
247 |

Import interface wasi:messaging/producer@0.2.0-draft

248 |

The producer interface is used to send messages to a channel/topic.

249 |
250 |

Types

251 |

type client

252 |

client

253 |

254 | #### `type message` 255 | [`message`](#message) 256 |

257 | #### `type error` 258 | [`error`](#error) 259 |

260 | #### `type topic` 261 | [`topic`](#topic) 262 |

263 | ---- 264 |

Functions

265 |

send: func

266 |

Sends the message using the given client.

267 |
Params
268 | 273 |
Return values
274 |
    275 |
  • result<_, error>
  • 276 |
277 |

Export interface wasi:messaging/incoming-handler@0.2.0-draft

278 |
279 |

Types

280 |

type message

281 |

message

282 |

283 | #### `type error` 284 | [`error`](#error) 285 |

286 | #### `type topic` 287 | [`topic`](#topic) 288 |

289 | ---- 290 |

Functions

291 |

handle: func

292 |

Whenever this guest receives a message in one of the subscribed topics, the message is 293 | sent to this handler. The guest is responsible for matching on the topic and handling the 294 | message accordingly. Implementors (such as hosts) calling this interface should make their 295 | own decisions on how to handle errors returned from this function.

296 |
Params
297 | 300 |
Return values
301 |
    302 |
  • result<_, error>
  • 303 |
304 | --------------------------------------------------------------------------------