Switchboard module

Using the Switchboard module to extend Channels.

CrateDescriptionDocs
selium-switchboardClient library that applications implementdocs.rs
selium-switchboard-coreInternal library that holds shared typesdocs.rs
selium-switchboard-protocolInternal library that defines the client-server protocoldocs.rs
selium-switchboard-serverWASM module that manages state and orchestrates channelsN/A

Switchboard is a declarative extension to the built in channels API. Every time a process creates, removes or modifies an endpoint (publisher, RPC server etc.), the Switchboard module computes the minimal channel wiring needed to fulfil the current state. This relieves developers from having to manage their own channels, and optimises the number of hops a message takes to reach its destination.

Switchboard also provides enhanced messaging patterns on top of the built in Reader and Writer types, which you can read about below.

Usage

The Switchboard server registers itself as a singleton (selium.switchboard.singleton). Processes can easily obtain a handle to the Switchboard via the global Context.

To start the server module:

selium-runtime --module 'path=modules/selium_switchboard_server.wasm;capabilities=ChannelLifecycle,ChannelReader,ChannelWriter,SingletonRegistry'

Messaging patterns

The client library gives you typed wrappers built on top of native channels:

  • Publish/Subscribe: Publisher<T> and Subscriber<T>
  • Fanout: Fanout<T> load-balances a stream across subscribers using a basic round-robin algorithm
  • Request/Response (RPC): Client<Req, Rep> and Server<Req, Rep>

Endpoints have built in connectivity rules that prevent incompatible endpoints from connecting to one another. For example, a Publisher cannot connect to a Request.

Example

#[entrypoint]
async fn start(ctx: Context, server_endpoint: GuestResourceId) -> Result<()> {
    let switchboard = ctx.require::<Switchboard>().await;
    
    let mut client = Client::create(&switchboard).await?;
    client.connect(&switchboard, server_endpoint).await?;
    client.request(...)
}