-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8a5579
commit 4e07b68
Showing
10 changed files
with
130 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
use actix_web::{post, web, Error, HttpResponse}; | ||
use futures_util::StreamExt as _; | ||
|
||
use crate::balancer::status_update::StatusUpdate; | ||
|
||
pub fn register(cfg: &mut web::ServiceConfig) { | ||
cfg.service(respond); | ||
} | ||
|
||
#[post("/stream")] | ||
#[post("/status_update")] | ||
async fn respond(mut payload: web::Payload) -> Result<HttpResponse, Error> { | ||
println!("Stream started"); | ||
|
||
while let Some(chunk) = payload.next().await { | ||
println!("Chunk: {:?}", chunk); | ||
match serde_json::from_slice::<StatusUpdate>(&chunk?) { | ||
Ok(status_update) => { | ||
println!("Received status update: {:?}", status_update); | ||
} | ||
Err(e) => { | ||
return Err(Error::from(e)); | ||
} | ||
} | ||
} | ||
|
||
println!("Stream ended"); | ||
|
||
Ok(HttpResponse::Ok().finish()) | ||
Ok(HttpResponse::Accepted().finish()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
use actix_web::{App, HttpServer}; | ||
use futures::future; | ||
use std::net::SocketAddr; | ||
|
||
use crate::balancer::http_route; | ||
use crate::errors::result::Result; | ||
|
||
pub async fn handle(_management_addr: &url::Url, _reverseproxy_addr: &url::Url) -> Result<()> { | ||
Ok( | ||
pub async fn handle(management_addr: &SocketAddr, reverseproxy_addr: &SocketAddr) -> Result<()> { | ||
let management_server = | ||
HttpServer::new(move || App::new().configure(http_route::receive_status_update::register)) | ||
.bind("127.0.0.1:8095")? | ||
.run() | ||
.await?, | ||
) | ||
.bind(management_addr)? | ||
.run(); | ||
|
||
let reverseproxy_server = | ||
HttpServer::new(move || App::new().configure(http_route::receive_status_update::register)) | ||
.bind(reverseproxy_addr)? | ||
.run(); | ||
|
||
future::try_join(management_server, reverseproxy_server).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.