#webassembly #wasm #wasmcloud #wapc #actors

wasmcloud-host

A secure, distributed, WebAssembly actor model runtime for the cloud, edge, and everything in between

10 unstable releases (3 breaking)

0.18.2 May 13, 2021
0.18.1 Apr 29, 2021
0.17.0 Apr 13, 2021
0.16.1 Apr 9, 2021
0.15.0 Feb 16, 2021

#69 in WebAssembly

Download history 56/week @ 2021-02-23 83/week @ 2021-03-02 37/week @ 2021-03-09 12/week @ 2021-03-16 64/week @ 2021-03-23 40/week @ 2021-03-30 57/week @ 2021-04-06 106/week @ 2021-04-13 93/week @ 2021-04-20 94/week @ 2021-04-27 52/week @ 2021-05-04 54/week @ 2021-05-11 27/week @ 2021-05-18 18/week @ 2021-05-25 21/week @ 2021-06-01 42/week @ 2021-06-08

268 downloads per month
Used in 2 crates

Apache-2.0

325KB
7.5K SLoC

Gitpod ready-to-code Crates.io Rust Build Documentation Rustdocs

wasmCloud Host

Open in Gitpod

wasmCloud is a secure, distributed actor platform with an autonomous mesh network built for bridging disparate and far-flung infrastructure.

By default a wasmCloud host will start in offline mode and only allow "local" scheduling of actors and capabilities. If you choose to opt-in to the lattice, you can use NATS as a message broker to provide the infrastructure for wasmCloud's self-forming, self-healing network. If you then want even more power, you can choose to override the capability provider used for managing the shared state within a lattice.

Local development on your workstation is easy and simple by default, and you should only incur additional complexity as you move toward resilient, distributed production environments.

To start a runtime, simply add actors and capabilities to the host. For more information, take a look at the documentation and tutorials at wasmcloud.dev.

Example

The following example creates a new wasmCloud host in the default standalone (no lattice) mode. It then loads an actor that simply echoes back incoming HTTP requests as outbound HTTP responses. The HTTP server capability provider is loaded so that the actor can receive web requests. Note that the link definition (configuration of the link between the actor and the capability provider) can be defined in any order. The host runtime automatically establishes links as soon as all related parties are up and running inside a host or a lattice.

use wasmcloud_host::{HostBuilder, Actor, NativeCapability};
use std::collections::HashMap;
use std::error::Error;
use std::time::Duration;
use actix_rt::time::sleep;
use reqwest;

const WEB_PORT: u32 = 8080;

#[actix_rt::main]
async fn main() -> Result<(), Box<dyn Error + Sync +Send>> {
    let h = HostBuilder::new().build();
    h.start().await?;
    let echo = Actor::from_file("../../tests/modules/echo.wasm")?;
    let actor_id = echo.public_key();
    h.start_actor(echo).await?;

    // Read a cross-platform provider archive file
    let arc = par_from_file("../../tests/modules/httpserver.par.gz")?;
    let websrv = NativeCapability::from_archive(&arc, None)?;
    let websrv_id = websrv.id();

    let mut webvalues: HashMap<String, String> = HashMap::new();
    webvalues.insert("PORT".to_string(), format!("{}", WEB_PORT));
    // Establish a link between the actor and a capability provider
    h.set_link(
        &actor_id,
        "wasmcloud:httpserver",
        None,
        websrv_id,
        webvalues,
    )
    .await?;
    // Start the web server provider (which auto-establishes the link)
    h.start_native_capability(websrv).await?;
    // Let the web server start
    sleep(Duration::from_millis(500)).await;
    let url = format!("http://localhost:{}/demo?test=kthxbye", WEB_PORT);

    let resp = reqwest::get(&url).await?;
    assert!(resp.status().is_success());
    let v: serde_json::Value = serde_json::from_slice(&resp.bytes().await?)?;
    assert_eq!("test=kthxbye", v["query_string"].as_str().unwrap());

    Ok(())
}

For more examples, refer to the integration tests located at the base of this repository

Dependencies

~32MB
~693K SLoC