Skip to content

Repository files navigation

Spawn Rust SDK

syntax="proto3";
packagedomain;
messageState {
repeatedstringlanguages=1;
}
messageRequest {
stringlanguage=1;
}
messageReply {
stringresponse=1;
}
use spawn_examples::domain::domain::{Reply,Request,State};use spawn_rs::{value::Value,Context,Message};use log::info;pubfnset_language(msg:Message,ctx:Context) -> Value{info!("Actor msg: {:?}", msg);returnmatch msg.body::<Request>(){Ok(request) => {let lang = request.language;info!("Setlanguage To: {:?}", lang);letmut reply = Reply::default();
reply.response = lang;match&ctx.state::<State>(){Some(state) => Value::new().state::<State>(&state.as_ref().unwrap(),"domain.State".to_string()).response(&reply,"domain.Reply".to_string()).to_owned(),
_ => Value::new().state::<State>(&State::default(),"domain.State".to_string()).response(&reply,"domain.Reply".to_string()).to_owned(),}}Err(_e) => Value::new().state::<State>(&State::default(),"domain.State".to_string()).to_owned(),};}pubfnset_language_with_timer(msg:Message,ctx:Context) -> Value{info!("Actor msg: {:?}", msg);returnmatch msg.body::<Request>(){Ok(request) => {let lang = request.language;info!("Setlanguage To: {:?}", lang);letmut reply = Reply::default();
reply.response = lang;match&ctx.state::<State>(){Some(state) => Value::new().state::<State>(&state.as_ref().unwrap(),"domain.State".to_string()).response(&reply,"domain.Reply".to_string()).to_owned(),
_ => Value::new().state::<State>(&State::default(),"domain.State".to_string()).response(&reply,"domain.Reply".to_string()).to_owned(),}}Err(_e) => Value::new().state::<State>(&State::default(),"domain.State".to_string()).to_owned(),};}
externcrate env_logger;externcrate prost_types;externcrate rocket;mod joe;use actors::joe::{set_language, set_language_with_timer};use spawn_rs::actor::{ActorDefinition,ActorSettings,Kind};use spawn_rs::spawn::Spawn;#[rocket::main]asyncfnmain() -> Result<(), rocket::Error>{letmut spawn:Spawn = Spawn::new().create("spawn-system".to_string()).with_service_name(env!("CARGO_PKG_NAME").to_string())// optional.with_service_version(env!("CARGO_PKG_VERSION").to_string())// optional.with_proxy_port(9003).with_actor(ActorDefinition::new().with_settings(ActorSettings::new().name("joe".to_owned()).kind(Kind::NAMED).stateful(true).deactivated_timeout(30000)// optional.snapshot_timeout(10000)// optional.to_owned(),).with_action("setLanguage".to_owned(), set_language).with_timer_action("set_language_with_timer".to_owned(),
set_language_with_timer,1000,),).clone();
spawn.start().await?;Ok(())}

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

5 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages