pub fn start(agg: ApiAggregator, config: ServiceApiConfig) {
    let (system_tx, system_rx) = mpsc::channel();
    let (api_runtime_tx, api_runtime_rx) = mpsc::channel();

    let api_servers = config.api_servers.clone();

    let system_thread = thread::spawn(move || -> ::std::result::Result<(), failure::Error> {
        let system = System::new("http-server");

        let api_handlers = api_servers.iter().map(|api_server| {
            let access = api_server.access;
            let listen_address = api_server.listen_address.clone();
            let agg = agg.clone();

            println!("{} rest API serving at {}", access, listen_address);
            HttpServer::new(move || create_app(&agg, access))
                .bind(listen_address)
                .map(|server| server.start())
        });

        system_tx.send(System::current())?;
        for handler in api_handlers {
            api_runtime_tx.send(handler?)?;
        }

        trace!("starting server...");

        println!("\nSystem Ready.");

        eventstream::emit(Event::Startup());

        // Starts actix-web runtime.
        let code = system.run();

        trace!("Actix runtime finished with code {}", code);
        ensure!(
            code == 0,
            "Actix runtime finished with the non zero error code: {}",
            code
        );

        Ok(())
    });

    let api_servers = config.api_servers.clone();

    // Receives addresses of runtime items.
    let system = system_rx
        .recv()
        .map_err(|_| format_err!("Unable to receive actix system handle"));

    if let Err(e) = &system {
        error!("{}", e);
    }

    if let Err(er) = system_thread.join().unwrap() {
        eprintln!("ERROR: Cannot start server. {}", er);
    }

    println!("done.");
}
/// Start API server berdasarkan konfigurasi yang ada.
Start API server berdasarkan konfigurasi yang ada.
Start API server berdasarkan konfigurasi yang ada .
pub fn start(agg: ApiAggregator, config: ServiceApiConfig) {
    let (system_tx, system_rx) = mpsc::channel();
    let (api_runtime_tx, api_runtime_rx) = mpsc::channel();
    let api_servers = config.api_servers.clone();
    let system_thread = thread::spawn(move || -> ::std::result::Result<(), failure::Error> {
        let system = System::new("http-server");
        let api_handlers = api_servers.iter().map(|api_server| {
            let access = api_server.access;
            let listen_address = api_server.listen_address.clone();
            let agg = agg.clone();
            println!("{} rest API serving at {}", access, listen_address);
            HttpServer::new(move || create_app(&agg, access))
                .bind(listen_address)
                .map(|server| server.start())
        });
        system_tx.send(System::current())?;
        for handler in api_handlers {
            api_runtime_tx.send(handler?)?;
        }
        trace!("starting server...");
        println!("\nSystem Ready.");
        eventstream::emit(Event::Startup());
        // Starts actix-web runtime.
        let code = system.run();
        trace!("Actix runtime finished with code {}", code);
        ensure!(
            code == 0,
            "Actix runtime finished with the non zero error code: {}",
            code
        );
        Ok(())
    });
    let api_servers = config.api_servers.clone();
    // Receives addresses of runtime items.
    let system = system_rx
        .recv()
        .map_err(|_| format_err!("Unable to receive actix system handle"));
    if let Err(e) = &system {
        error!("{}", e);
    }
    if let Err(er) = system_thread.join().unwrap() {
        eprintln!("ERROR: Cannot start server. {}", er);
    }
    println!("done.");
}
pub fn start ( agg : ApiAggregator , config : ServiceApiConfig ) { let ( system_tx , system_rx ) = mpsc :: channel ( ) ; let ( api_runtime_tx , api_runtime_rx ) = mpsc :: channel ( ) ; let api_servers = config . api_servers . clone ( ) ; let system_thread = thread :: spawn ( move | | -> :: std :: result :: Result < ( ) , failure :: Error > { let system = System :: new ( " " ) ; let api_handlers = api_servers . iter ( ) . map ( | api_server | { let access = api_server . access ; let listen_address = api_server . listen_address . clone ( ) ; let agg = agg . clone ( ) ; println ! ( " " access listen_address ) ; HttpServer :: new ( move | | create_app ( & agg , access ) ) . bind ( listen_address ) . map ( | server | server . start ( ) ) } ) ; system_tx . send ( System :: current ( ) ) ? ; for handler in api_handlers { api_runtime_tx . send ( handler ? ) ? ; } trace ! ( " " ) ; println ! ( " \n " ) ; eventstream :: emit ( Event :: Startup ( ) ) ; // Starts actix-web runtime. let code = system . run ( ) ; trace ! ( " " code ) ; ensure ! ( code 0 " " code ) ; Ok ( ( ) ) } ) ; let api_servers = config . api_servers . clone ( ) ; // Receives addresses of runtime items. let system = system_rx . recv ( ) . map_err ( | _ | format_err ! ( " " ) ) ; if let Err ( e ) = & system { error ! ( " " e ) ; } if let Err ( er ) = system_thread . join ( ) . unwrap ( ) { eprintln ! ( " " er ) ; } println ! ( " " ) ; }
Start API server berdasarkan konfigurasi yang ada.
Start API server berdasarkan konfigurasi yang ada .
agg
ApiAggregator
config
ServiceApiConfig
agg
ApiAggregator
config
ServiceApiConfig