Skip to main content

Cluster

Struct Cluster 

Source
pub struct Cluster<T: Transport> { /* private fields */ }
Expand description

Connections plus the cluster map.

Implementations§

Source§

impl<T: Transport> Cluster<T>

Source

pub async fn connect( transport: T, bootstrap: &[String], client_id: &str, ) -> Result<Self>

Connect to the first reachable bootstrap address and load metadata.

§Errors

If no bootstrap address answers.

Source

pub fn set_credentials(&mut self, credentials: Credentials)

Authenticate every connection with credentials.

Must be set before the first request; connections already open are not re-authenticated, because Kafka has no way to do so.

Source

pub fn set_request_timeout(&mut self, timeout: Duration)

How long a request may take before its connection is dropped as broken.

Source

pub fn set_allow_auto_topic_creation(&mut self, allow: bool)

Whether metadata requests may create missing topics. See the field.

Source

pub fn metadata(&self) -> &Metadata

The cluster map, for callers that want to inspect leadership.

Source

pub async fn refresh_metadata(&mut self, topic: &str) -> Result<()>

Ask any broker for topic’s metadata and merge it in.

§Errors

If no broker answers, or the topic carries an error code.

Source

pub fn set_metadata_max_age(&mut self, age: Duration)

How long a topic’s metadata may go unrefreshed before a lookup re-reads it. See the refreshed_at field.

Source

pub fn is_metadata_stale(&self, topic: &str) -> bool

Whether this topic’s metadata is older than the maximum age. A topic never read is stale.

Source

pub async fn refresh_if_stale( &mut self, topic: &str, ) -> Result<Option<(i32, i32)>>

Re-read this topic if it is stale, and report (before, after) if its partition count grew.

Only growth: Kafka has no operation that removes partitions from a live topic, so a smaller number is a transient answer — a broker that has not caught up, a topic mid-creation — and acting on it would move every key twice. A topic seen for the first time reports no growth either; there is nothing to have grown from.

§Errors

If the refresh fails.

Source

pub fn forget_topic(&mut self, topic: &str)

Forget a topic that has been deleted — its count and every leader.

Source

pub async fn refresh_cluster(&mut self) -> Result<()>

Refresh brokers and the controller without naming a topic.

An empty topic list is not the same as no topic list: None asks for every topic in the cluster, which on a large cluster is a large answer for information this does not want.

§Errors

If no broker answers.

Source

pub async fn controller_addr(&mut self) -> Result<String>

The controller’s address, refreshing if it is unknown.

§Errors

If metadata cannot be refreshed, or no controller is elected — which happens briefly during a controller election and is a wait, not a failure, so callers retry it.

Source

pub fn invalidate_controller(&mut self)

Forget which broker is the controller, after it said it is not.

Source

pub async fn leader_addr( &mut self, topic: &str, partition: i32, ) -> Result<String>

The address of topic/partition’s leader, refreshing if unknown.

§Errors

If metadata cannot be refreshed, or the partition still has no leader afterwards — which is what a partition mid-election looks like, and is Error::NoLeader so a caller can back off and try again rather than treat it as fatal.

Source

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

How many partitions topic has, refreshing metadata if the client has not seen it yet.

§Errors

If metadata cannot be refreshed, or the topic has no partitions after it.

Source

pub fn invalidate(&mut self, topic: &str, partition: i32)

Forget one partition’s leader after the broker said it is not the leader. Per partition on purpose — see barnabas_core::metadata.

Source

pub fn connection_count(&self) -> usize

Number of open connections. Exposed because connection count is a real cost of the per-core design, and something a caller may want to watch.

Auto Trait Implementations§

§

impl<T> Freeze for Cluster<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Cluster<T>

§

impl<T> Send for Cluster<T>
where T: Send, <T as Transport>::Stream: Send,

§

impl<T> Sync for Cluster<T>
where T: Sync, <T as Transport>::Stream: Sync,

§

impl<T> Unpin for Cluster<T>
where T: Unpin, <T as Transport>::Stream: Unpin,

§

impl<T> UnsafeUnpin for Cluster<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Cluster<T>

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, 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.