I'm trying to implement the following flow in Rust:
- an entry (JSON) is submitted to an Actix web listener and processed
- the entry is submitted to an "observable queue"
- An Actix Web client is notified
- The client sends it off (via HTTP) to a backend. This might fail
- If it failed the entry is handed to a "timer" if that submission has failed less than 10 times
- After 30 seconds the timer resubmits the entry to the queue and the flow resumes at 3
I solved that using vert.x and Java (GitHub project) and want to use it as sample project learning Rust.
Update:
Found the actix documentation and implemented and Actix::Actor which covers 1->4
use crate::comments_entry::BlogSubmission;
use actix::prelude::*;
pub struct CommentStore {}
impl Actor for CommentStore {
type Context = Context<Self>;
}
impl Handler<BlogSubmission> for CommentStore {
type Result = String;
fn handle(&mut self, _msg: BlogSubmission, _ctx: &mut Context<Self>) -> Self::Result {
// Here goes #4 send to backebd
println!("{:?}", _msg);
"It worked".to_string()
}
}
Which narrows my questions substantially:
- How can I build a delay timer?
- When I start the actor in my
main()
method, which also starts the web server usinglet c_store = CommentStore::start(CommentStore {});
i get the Actor's address inc_store
. However I need to send to the actor in one of the async functions specified as Route targets. How do I best handover the address. Global variables seem not to be the answer.
Current main function
Help is very much appreciated