use std::collections::HashMap;
use wascc_host::{Actor, Host, NativeCapability};
const ACTOR_SUBJECT: &str = "MCYWHMJW5VW5U7ZRDQV7JU45GHSR2SA6OZJ2MPHQCFALR2CGFA2NAMZM";
fn main() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
env_logger::init();
let host = Host::new();
host.add_actor(Actor::from_file("./examples/.assets/multibinding.wasm")?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_httpsrv.so",
None,
)?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_redis.so",
Some("source1".to_string()),
)?)?;
host.add_native_capability(NativeCapability::from_file(
"./examples/.assets/libwascc_redis.so",
Some("source2".to_string()),
)?)?;
host.set_binding(
ACTOR_SUBJECT,
"wascc:http_server",
None,
generate_port_config(8081),
)?;
host.set_binding(
ACTOR_SUBJECT,
"wascc:keyvalue",
Some("source1".to_string()),
redis_config(0),
)?;
host.set_binding(
ACTOR_SUBJECT,
"wascc:keyvalue",
Some("source2".to_string()),
redis_config(1),
)?;
std::thread::park();
Ok(())
}
fn redis_config(dbindex: u32) -> HashMap<String, String> {
let mut hm = HashMap::new();
hm.insert(
"URL".to_string(),
format!("redis://127.0.0.1:6379/{}", dbindex),
);
hm
}
fn generate_port_config(port: u16) -> HashMap<String, String> {
let mut hm = HashMap::new();
hm.insert("PORT".to_string(), port.to_string());
hm
}