-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: connector support http export transport (#233)
* feat: connector support http export transport * fix: update header for connector http transport * chore: resolve comment about derive_more and http handling * chore: update the documents relating to connector server
- Loading branch information
1 parent
3276dc7
commit a1453a0
Showing
11 changed files
with
104 additions
and
13 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
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
54 changes: 54 additions & 0 deletions
54
servers/media-server/src/server/connector/transports/http.rs
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::{io, marker::PhantomData}; | ||
|
||
use async_trait::async_trait; | ||
use prost::Message; | ||
use serde::Serialize; | ||
|
||
use super::{ConnectorTransporter, Format}; | ||
|
||
pub struct HttpTransporter<M: Message + Serialize> { | ||
client: reqwest::Client, | ||
url: String, | ||
format: Format, | ||
_tmp: PhantomData<M>, | ||
} | ||
|
||
impl<M: Message + Serialize> HttpTransporter<M> { | ||
pub fn new(url: &str, format: &Format) -> Self { | ||
Self { | ||
client: reqwest::Client::new(), | ||
url: url.to_string(), | ||
format: format.clone(), | ||
_tmp: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<M: Message + Serialize> ConnectorTransporter<M> for HttpTransporter<M> { | ||
async fn send(&mut self, data: M) -> Result<(), io::Error> { | ||
let res = match self.format { | ||
Format::Json => self.client.post(&self.url).json(&data).send().await, | ||
Format::Protobuf => self.client.post(&self.url).body(data.encode_to_vec()).header("Content-Type", "application/octet-stream").send().await, | ||
}; | ||
|
||
match res { | ||
Ok(res) => { | ||
if res.status().is_success() { | ||
log::debug!("Data sent to {}", self.url); | ||
return Ok(()); | ||
} | ||
log::error!("Failed to send data to {}: {:?}", self.url, res); | ||
return Err(io::Error::new(io::ErrorKind::Other, "Failed to send data")); | ||
} | ||
Err(e) => { | ||
log::error!("Failed to send data to {}: {:?}", self.url, e); | ||
return Err(io::Error::new(io::ErrorKind::Other, "Failed to send data")); | ||
} | ||
}; | ||
} | ||
|
||
async fn close(&mut self) -> Result<(), io::Error> { | ||
Ok(()) | ||
} | ||
} |
13 changes: 12 additions & 1 deletion
13
servers/media-server/src/server/connector/transports/mod.rs
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