forked from Azure/azure-sdk-for-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dan Chiarlone <[email protected]>
- Loading branch information
Showing
8 changed files
with
435 additions
and
308 deletions.
There are no files selected for viewing
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,65 +1,67 @@ | ||
// use azure_messaging_servicebus::prelude::*; | ||
// use chrono::Duration; | ||
use azure_messaging_servicebus::prelude::*; | ||
use chrono::Duration; | ||
use std::error::Error; | ||
|
||
// async fn send( | ||
// s: String, | ||
// service_bus_namespace: String, | ||
// event_hub_name: String, | ||
// policy_name: String, | ||
// policy_key: String, | ||
// ) -> Result<(), Box<dyn Error>> { | ||
// let mut client = Client::new( | ||
// service_bus_namespace.to_owned(), | ||
// event_hub_name.to_owned(), | ||
// policy_name.to_owned(), | ||
// policy_key.to_owned(), | ||
// )?; | ||
async fn send( | ||
s: String, | ||
service_bus_namespace: String, | ||
event_hub_name: String, | ||
policy_name: String, | ||
policy_key: String, | ||
) -> Result<(), Box<dyn Error>> { | ||
let http_client = azure_core::new_http_client(); | ||
let mut client = Client::new( | ||
http_client, | ||
service_bus_namespace.to_owned(), | ||
event_hub_name.to_owned(), | ||
policy_name.to_owned(), | ||
policy_key.to_owned(), | ||
)?; | ||
|
||
// println!("before {:?} message send!", s); | ||
// match client.send_event(&s, Duration::days(1)).await { | ||
// Ok(_) => println!("{:?} message sent!", s), | ||
println!("before {:?} message send!", s); | ||
match client.send_event(&s, Duration::days(1)).await { | ||
Ok(_) => println!("{:?} message sent!", s), | ||
|
||
// Err(error) => println!("{:?} failed to send message", error), | ||
// } | ||
Err(error) => println!("{:?} failed to send message", error), | ||
} | ||
|
||
// Ok(()) | ||
// } | ||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn Error>> { | ||
// // First we retrieve the account name and master key from environment variables. | ||
// // We expect master keys (ie, not resource constrained) | ||
// let service_bus_namespace = std::env::var("AZURE_SERVICE_BUS_NAMESPACE") | ||
// .expect("Set env variable AZURE_SERVICE_BUS_NAMESPACE first!"); | ||
// let event_hub_name = std::env::var("AZURE_EVENT_HUB_NAME") | ||
// .expect("Set env variable AZURE_EVENT_HUB_NAME first!"); | ||
// let policy_name = | ||
// std::env::var("AZURE_POLICY_NAME").expect("Set env variable AZURE_POLICY_NAME first!"); | ||
// let policy_key = | ||
// std::env::var("AZURE_POLICY_KEY").expect("Set env variable AZURE_POLICY_KEY first!"); | ||
// First we retrieve the account name and master key from environment variables. | ||
// We expect master keys (ie, not resource constrained) | ||
let service_bus_namespace = std::env::var("AZURE_SERVICE_BUS_NAMESPACE") | ||
.expect("Set env variable AZURE_SERVICE_BUS_NAMESPACE first!"); | ||
let event_hub_name = std::env::var("AZURE_EVENT_HUB_NAME") | ||
.expect("Set env variable AZURE_EVENT_HUB_NAME first!"); | ||
let policy_name = | ||
std::env::var("AZURE_POLICY_NAME").expect("Set env variable AZURE_POLICY_NAME first!"); | ||
let policy_key = | ||
std::env::var("AZURE_POLICY_KEY").expect("Set env variable AZURE_POLICY_KEY first!"); | ||
|
||
// let messages = vec![ | ||
// "These", "are", "useless", "messages", "provided", "for", "free", "with", "love", | ||
// ]; | ||
// println!( | ||
// "Sending the following messages: {:?}. \ | ||
// Please note they will be sent out of order!", | ||
// messages | ||
// ); | ||
let messages = vec![ | ||
"These", "are", "useless", "messages", "provided", "for", "free", "with", "love", | ||
]; | ||
println!( | ||
"Sending the following messages: {:?}. \ | ||
Please note they will be sent out of order!", | ||
messages | ||
); | ||
|
||
// let mut v = Vec::new(); | ||
// for s in messages.into_iter() { | ||
// v.push(send( | ||
// s.to_owned(), | ||
// service_bus_namespace.to_owned(), | ||
// event_hub_name.to_owned(), | ||
// policy_name.to_owned(), | ||
// policy_key.to_owned(), | ||
// )) | ||
// } | ||
let mut v = Vec::new(); | ||
for s in messages.into_iter() { | ||
v.push(send( | ||
s.to_owned(), | ||
service_bus_namespace.to_owned(), | ||
event_hub_name.to_owned(), | ||
policy_name.to_owned(), | ||
policy_key.to_owned(), | ||
)) | ||
} | ||
|
||
// futures::future::join_all(v).await; | ||
futures::future::join_all(v).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/// A specialized Result type. | ||
pub type Result<T> = std::result::Result<T, Error>; | ||
|
||
#[non_exhaustive] | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
CoreError(#[from] azure_core::Error), | ||
#[error("Parse error: {0}")] | ||
ParseError(#[from] azure_core::ParseError), | ||
#[error("Permission error: {0}")] | ||
PermissionError(#[from] azure_core::PermissionError), | ||
#[error("Parse bool error: {0}")] | ||
ParseBoolError(#[from] std::str::ParseBoolError), | ||
#[error("To str error: {0}")] | ||
ToStrError(#[from] http::header::ToStrError), | ||
#[error("URL parse error: {0}")] | ||
UrlParseError(#[from] url::ParseError), | ||
#[error("Date time parse error: {0}")] | ||
DateTimeParseError(#[from] chrono::format::ParseError), | ||
#[error("HTTP error: {0}")] | ||
HttpError(#[from] http::Error), | ||
#[error("Traversing error: {0}")] | ||
TraversingError(#[from] azure_core::TraversingError), | ||
#[error("From UTF-8 error: {0}")] | ||
FromUtf8Error(#[from] std::string::FromUtf8Error), | ||
#[error("Invalid status code: {0:?}")] | ||
InvalidStatusCode(#[from] http::status::InvalidStatusCode), | ||
#[error("UTF-8 conversion error: {0}")] | ||
Utf8Error(#[from] std::str::Utf8Error), | ||
#[error("base64 decode error: {0}")] | ||
Base64DecodeError(#[from] base64::DecodeError), | ||
#[error("A required header is missing: {0}")] | ||
MissingHeaderError(String), | ||
#[error( | ||
"An expected JSON node is missing: {} of expected type {}", | ||
value, | ||
expected_type | ||
)] | ||
MissingValueError { | ||
value: String, | ||
expected_type: String, | ||
}, | ||
#[error("Parse int error: {0}")] | ||
ParseIntError(#[from] std::num::ParseIntError), | ||
#[error("Header not found: {0}")] | ||
HeaderNotFound(String), | ||
#[error("Error parsing the transaction response: {0:?}")] | ||
TransactionResponseParseError(String), | ||
#[error("Generic error: {0}")] | ||
GenericErrorWithText(String), | ||
#[error("Operation not supported. Operation == {0}, reason == {1}")] | ||
OperationNotSupported(String, String), | ||
#[error("UnexpectedXMLError: {0}")] | ||
UnexpectedXMLError(String), | ||
#[error("digest length {0} bytes instead of 16")] | ||
DigestNot16BytesLong(usize), | ||
#[error("CRC64 length {0} bytes instead of 8")] | ||
CRC64Not8BytesLong(usize), | ||
#[error("At least one of these headers must be present: {0:?}")] | ||
HeadersNotFound(Vec<String>), | ||
#[error("error writing the header value: {0}")] | ||
InvalidHeaderValue(#[from] azure_core::HttpHeaderError), | ||
#[error("error generating hmac: {0}")] | ||
Hmac(#[from] hmac::digest::InvalidLength), | ||
} | ||
|
||
impl From<azure_core::error::Error> for Error { | ||
fn from(err: azure_core::error::Error) -> Self { | ||
Self::CoreError(err.into()) | ||
} | ||
} | ||
|
||
impl From<azure_core::HttpError> for Error { | ||
fn from(error: azure_core::HttpError) -> Self { | ||
Self::CoreError(azure_core::Error::Http(error)) | ||
} | ||
} |
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.