#![allow(dead_code)]
use super::error::StreamError;
use super::types::TopicPartition;
use std::collections::HashMap;
pub struct AdminClient {
bootstrap_servers: String,
}
impl AdminClient {
pub fn new(bootstrap_servers: impl Into<String>) -> Self {
Self {
bootstrap_servers: bootstrap_servers.into(),
}
}
pub fn bootstrap_servers(&self) -> &str {
&self.bootstrap_servers
}
pub async fn create_topic(&self, name: &str, config: TopicConfig) -> Result<(), StreamError> {
let _ = (name, config);
Ok(())
}
pub async fn delete_topic(&self, name: &str) -> Result<(), StreamError> {
let _ = name;
Ok(())
}
pub async fn list_topics(&self) -> Result<Vec<String>, StreamError> {
Ok(Vec::new())
}
pub async fn describe_topic(&self, name: &str) -> Result<TopicInfo, StreamError> {
Ok(TopicInfo {
name: name.to_string(),
partitions: 1,
replication_factor: 1,
config: HashMap::new(),
})
}
pub async fn list_consumer_groups(&self) -> Result<Vec<String>, StreamError> {
Ok(Vec::new())
}
pub async fn describe_consumer_group(&self, group: &str) -> Result<GroupInfo, StreamError> {
Ok(GroupInfo {
group_id: group.to_string(),
state: GroupState::Empty,
members: Vec::new(),
coordinator: None,
})
}
pub async fn delete_consumer_group(&self, _group: &str) -> Result<(), StreamError> {
Ok(())
}
pub async fn reset_offsets(
&self,
_group: &str,
_topic: &str,
_offset: OffsetSpec,
) -> Result<(), StreamError> {
Ok(())
}
pub async fn close(&self) -> Result<(), StreamError> {
Ok(())
}
}
#[derive(Debug, Clone, Default)]
pub struct TopicConfig {
pub partitions: u32,
pub replication_factor: u16,
pub max_entries: Option<u64>,
pub retention_ms: Option<u64>,
pub config: HashMap<String, String>,
}
impl TopicConfig {
pub fn new() -> Self {
Self {
partitions: 1,
replication_factor: 1,
..Default::default()
}
}
pub fn partitions(mut self, n: u32) -> Self {
self.partitions = n;
self
}
pub fn replication_factor(mut self, n: u16) -> Self {
self.replication_factor = n;
self
}
pub fn max_entries(mut self, n: u64) -> Self {
self.max_entries = Some(n);
self
}
pub fn retention_ms(mut self, ms: u64) -> Self {
self.retention_ms = Some(ms);
self
}
}
#[derive(Debug, Clone)]
pub struct TopicInfo {
pub name: String,
pub partitions: u32,
pub replication_factor: u16,
pub config: HashMap<String, String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GroupState {
Empty,
Rebalancing,
Stable,
Dead,
}
#[derive(Debug, Clone)]
pub struct GroupInfo {
pub group_id: String,
pub state: GroupState,
pub members: Vec<MemberInfo>,
pub coordinator: Option<String>,
}
#[derive(Debug, Clone)]
pub struct MemberInfo {
pub member_id: String,
pub client_id: String,
pub client_host: String,
pub assignment: Vec<TopicPartition>,
}
#[derive(Debug, Clone)]
pub enum OffsetSpec {
Earliest,
Latest,
Offset(u64),
Timestamp(u64),
}