Skip to main content

AdminClient

Struct AdminClient 

Source
pub struct AdminClient { /* private fields */ }
Expand description

Kafka admin client for cluster administration.

Implementations§

Source§

impl AdminClient

Source

pub fn builder() -> AdminClientBuilder

Create a new admin client builder.

Source

pub async fn create_topics( &self, topics: Vec<NewTopic>, timeout: Duration, ) -> Result<Vec<CreateTopicResult>>

Create topics.

Source

pub async fn delete_topics( &self, topics: Vec<String>, timeout: Duration, ) -> Result<Vec<DeleteTopicResult>>

Delete topics.

Source

pub async fn create_partitions( &self, topic: impl Into<String>, new_total_count: i32, timeout: Duration, ) -> Result<CreatePartitionsResult>

Increase the number of partitions for a topic.

Note: Partition count can only be increased, never decreased.

Source

pub async fn describe_topic_config( &self, topic: &str, ) -> Result<Vec<ConfigEntry>>

Describe configuration for a topic.

Source

pub async fn describe_broker_config( &self, broker_id: i32, ) -> Result<Vec<ConfigEntry>>

Describe configuration for a broker.

Source

pub async fn alter_topic_config( &self, topic: &str, configs: HashMap<String, String>, ) -> Result<AlterConfigResult>

Alter configuration for a topic.

Note: This replaces all dynamic configs. To modify a single config, first describe the topic config and then set all desired values.

Source

pub async fn list_topics(&self) -> Result<Vec<String>>

List all topics.

Source

pub async fn describe_topics(&self, topics: &[String]) -> Result<Vec<TopicInfo>>

Describe topics.

Source

pub async fn describe_cluster(&self) -> Result<ClusterDescription>

Describe the cluster.

Source

pub async fn partition_count(&self, topic: &str) -> Result<Option<usize>>

Get partition count for a topic.

Source

pub fn client_id(&self) -> &str

Get the client ID.

Source

pub fn request_timeout(&self) -> Duration

Get the request timeout.

Source

pub async fn describe_acls( &self, resource_type: AclResourceType, resource_name: Option<&str>, pattern_type: AclPatternType, principal: Option<&str>, host: Option<&str>, operation: AclOperation, permission_type: AclPermissionType, ) -> Result<DescribeAclsResult>

Describe ACLs matching a filter.

§Arguments
  • resource_type - Type of resource (Topic, Group, Cluster, etc.)
  • resource_name - Name of the resource (use None to match any)
  • pattern_type - Pattern type (Literal, Prefixed, Any)
  • principal - Principal (use None to match any)
  • host - Host (use None to match any)
  • operation - Operation (use Any to match all)
  • permission_type - Permission type (use Any to match all)
§Example
// Describe all ACLs for a specific topic
let result = admin.describe_acls(
    AclResourceType::Topic,
    Some("my-topic"),
    AclPatternType::Literal,
    None,
    None,
    AclOperation::Any,
    AclPermissionType::Any,
).await?;
Source

pub async fn describe_acls_with_filter( &self, filter: AclFilter, ) -> Result<DescribeAclsResult>

Describe ACLs matching a filter.

This is the preferred method for describing ACLs as it uses a structured filter object.

§Example
// Describe all ACLs for a specific topic
let filter = AclFilter::for_resource(AclResourceType::Topic, "my-topic");
let result = admin.describe_acls_with_filter(filter).await?;
Source

pub async fn create_acls( &self, acls: Vec<AclBinding>, ) -> Result<CreateAclsResult>

Create ACLs.

§Arguments
  • acls - List of ACL bindings to create
§Example
let acl = AclBinding::allow_read_topic("my-topic", "User:alice");
admin.create_acls(vec![acl]).await?;
Source

pub async fn delete_acls( &self, filters: Vec<AclBindingFilter>, ) -> Result<DeleteAclsResult>

Delete ACLs matching the specified filters.

§Arguments
  • filters - List of ACL binding filters to match for deletion
§Example
// Delete all ACLs for a specific topic
let filter = AclBindingFilter {
    resource_type: AclResourceType::Topic,
    resource_name: Some("my-topic".to_string()),
    pattern_type: AclPatternType::Literal,
    principal: None,
    host: None,
    operation: AclOperation::Any,
    permission_type: AclPermissionType::Any,
};
admin.delete_acls(vec![filter]).await?;
Source

pub async fn describe_groups( &self, group_ids: Vec<String>, ) -> Result<Vec<ConsumerGroupDescription>>

Describe consumer groups.

Returns detailed information about each group including state, members, and partition assignments.

§Example
let groups = admin.describe_groups(vec!["my-group".to_string()]).await?;
for group in &groups {
    println!("{}: state={}, members={}", group.group_id, group.state, group.members.len());
}
Source

pub async fn list_consumer_groups(&self) -> Result<Vec<ConsumerGroupListing>>

List all consumer groups on the cluster.

Returns a list of all consumer groups with their protocol types.

§Example
let groups = admin.list_consumer_groups().await?;
for group in &groups {
    println!("{} ({})", group.group_id, group.protocol_type);
}
Source

pub async fn delete_records( &self, offsets: HashMap<(String, i32), i64>, timeout: Duration, ) -> Result<Vec<DeleteRecordResult>>

Delete records from topic partitions before the specified offsets.

Records with offsets less than the specified offset for each partition will be marked for deletion. This adjusts the log start offset.

§Arguments
  • offsets - Map of (topic, partition) to the offset before which to delete
  • timeout - Operation timeout
§Example
use std::collections::HashMap;
let mut offsets = HashMap::new();
offsets.insert(("my-topic".to_string(), 0), 100i64);
let results = admin.delete_records(offsets, Duration::from_secs(30)).await?;
Source

pub async fn offset_for_leader_epoch( &self, partitions: Vec<(String, i32, i32)>, ) -> Result<Vec<LeaderEpochResult>>

Get the end offset for each partition at the given leader epoch.

This is used to detect log truncation after a leader change. For each topic-partition, the broker returns the end offset for the requested leader epoch. If the epoch is no longer valid, the broker returns the epoch and offset where the log was truncated.

§Arguments
  • partitions - List of (topic, partition, leader_epoch) tuples
§Example
let results = admin.offset_for_leader_epoch(
    vec![("my-topic".to_string(), 0, 5)]
).await?;
for r in &results {
    println!("{}:{} epoch={} end_offset={}", r.topic, r.partition, r.leader_epoch, r.end_offset);
}
Source

pub fn pool(&self) -> &Arc<ConnectionPool>

Get access to the connection pool.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more