1

I'm trying to implement the following flow in Rust: Threaded flow

  1. an entry (JSON) is submitted to an Actix web listener and processed
  2. the entry is submitted to an "observable queue"
  3. An Actix Web client is notified
  4. The client sends it off (via HTTP) to a backend. This might fail
  5. If it failed the entry is handed to a "timer" if that submission has failed less than 10 times
  6. 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 using let c_store = CommentStore::start(CommentStore {}); i get the Actor's address in c_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

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • 1
    "How can I build a delay timer?" guess something like https://docs.rs/tokio/0.2.18/tokio/time/index.html. – Stargateur Apr 19 '20 at 19:52
  • That probably works. Now checking how it fits with actix’s actor model. Turn your comment into an answer (and if possible hint on Q2) so you can get the recognition for your help – stwissel Apr 21 '20 at 07:33

0 Answers0