Skip to content

Latest commit

 

History

History
188 lines (188 loc) · 8.47 KB

messaging.md

File metadata and controls

188 lines (188 loc) · 8.47 KB

World messaging

Import interface wasi:messaging/types@0.2.0-draft


Types

resource client

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

variant error

Errors that can occur when using the messaging interface.

Variant Cases
  • timeout

    The request or operation timed out.

  • connection: string

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

  • other: string

    A catch all for other types of errors

resource message

A message with a binary payload and additional information

Functions

[static]client.connect: func

Params
  • name: string
Return values

[constructor]message: func

Params
  • topic: string
  • data: list<u8>
Return values

[method]message.topic: func

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

Params
Return values
  • string

[method]message.set-topic: func

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

Params
  • self: borrow<message>
  • topic: string

[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

Params
Return values
  • option<string>

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

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

Params
  • self: borrow<message>
  • content-type: string

[method]message.data: func

An opaque blob of data

Params
Return values
  • list<u8>

[method]message.set-data: func

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

Params
  • self: borrow<message>
  • data: list<u8>

[method]message.metadata: func

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

Params
Return values
  • option<list<(string, string)>>

[method]message.add-metadata: func

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

Params
  • self: borrow<message>
  • key: string
  • value: string

Import interface wasi:messaging/producer@0.2.0-draft

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


Types

type client

client

#### `type message` [`message`](#message)

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

----

Functions

send: func

Sends the message using the given client.

Params
Return values

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


Types

type message

message

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

----

Functions

handle: func

Whenever this guest receives a message in one of the subscribed channels, the message is sent to this handler. The guest is responsible for matching on the channel 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
Return values

subscribe: func

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

Return values
  • result<list<string>, error>