use crate::StartPosition;
use azure_core::{
error::ErrorKind as AzureErrorKind, http::Etag, time::OffsetDateTime, Error, Result,
};
use std::collections::HashMap;
#[derive(Debug, Default, Clone)]
pub struct Checkpoint {
pub fully_qualified_namespace: String,
pub event_hub_name: String,
pub consumer_group: String,
pub partition_id: String,
pub offset: Option<String>,
pub sequence_number: Option<i64>,
}
macro_rules! check_non_empty_parameter(
($field:expr) => {
if $field.is_empty() {
return Err(Error::with_message(AzureErrorKind::Other,
String::from("Required field ") + stringify!($field) + " is empty",
));
}
}
);
impl Checkpoint {
pub fn get_checkpoint_blob_prefix_name(
fully_qualified_namespace: &str,
event_hub_name: &str,
consumer_group: &str,
) -> Result<String> {
check_non_empty_parameter!(fully_qualified_namespace);
check_non_empty_parameter!(event_hub_name);
check_non_empty_parameter!(consumer_group);
Ok(fully_qualified_namespace.to_string()
+ "/"
+ event_hub_name
+ "/"
+ consumer_group
+ "/checkpoint/")
}
pub fn get_checkpoint_blob_name(
fully_qualified_namespace: &str,
event_hub_name: &str,
consumer_group: &str,
partition_id: &str,
) -> Result<String> {
check_non_empty_parameter!(partition_id);
Ok(Self::get_checkpoint_blob_prefix_name(
fully_qualified_namespace,
event_hub_name,
consumer_group,
)? + partition_id)
}
}
#[derive(Debug, Default, Clone)]
pub struct Ownership {
pub fully_qualified_namespace: String,
pub event_hub_name: String,
pub consumer_group: String,
pub partition_id: String,
pub owner_id: Option<String>,
pub etag: Option<Etag>,
pub last_modified_time: Option<OffsetDateTime>,
}
impl Ownership {
pub fn get_ownership_prefix_name(
fully_qualified_namespace: &str,
event_hub_name: &str,
consumer_group: &str,
) -> Result<String> {
check_non_empty_parameter!(fully_qualified_namespace);
check_non_empty_parameter!(event_hub_name);
check_non_empty_parameter!(consumer_group);
Ok(fully_qualified_namespace.to_string()
+ "/"
+ event_hub_name
+ "/"
+ consumer_group
+ "/ownership/")
}
pub fn get_ownership_name(
fully_qualified_namespace: &str,
event_hub_name: &str,
consumer_group: &str,
partition_id: &str,
) -> Result<String> {
check_non_empty_parameter!(fully_qualified_namespace);
check_non_empty_parameter!(event_hub_name);
check_non_empty_parameter!(consumer_group);
check_non_empty_parameter!(partition_id);
Ok(Self::get_ownership_prefix_name(
fully_qualified_namespace,
event_hub_name,
consumer_group,
)? + partition_id)
}
}
#[derive(Debug, Default)]
pub struct StartPositions {
pub per_partition: HashMap<String, StartPosition>,
pub default: StartPosition,
}