pub struct Connection { /* private fields */ }Expand description
A connection to a single Kafka broker.
Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn connect(
addr: SocketAddr,
options: ConnectionOptions,
) -> Result<Self, ClientError>
pub async fn connect( addr: SocketAddr, options: ConnectionOptions, ) -> Result<Self, ClientError>
Connect to addr, negotiate API versions, return a usable Connection.
§Errors
Returns an error when configuration is invalid, protocol encoding fails, the broker rejects the request, or transport I/O fails.
Sourcepub async fn connect_with_options(
addr: SocketAddr,
options: ConnectionOptions,
) -> Result<Self, ClientError>
pub async fn connect_with_options( addr: SocketAddr, options: ConnectionOptions, ) -> Result<Self, ClientError>
Connect to addr and honour options.security.
This method makes a secured (TLS/SASL) dial when a policy is set, and
a plaintext dial otherwise. It is the single connect entry point for
every metadata-client site (pool, admin, RLMM fetch loop), so the
plaintext-versus-secured branch cannot drift between them. The
plaintext (None) path is byte-identical to Self::connect.
§Errors
Propagates Self::connect / Self::connect_secured failures.
Sourcepub async fn connect_secured(
addr: SocketAddr,
options: ConnectionOptions,
security: &ClientSecurity,
) -> Result<Self, ClientError>
pub async fn connect_secured( addr: SocketAddr, options: ConnectionOptions, security: &ClientSecurity, ) -> Result<Self, ClientError>
Connect to addr and apply security (TLS then SASL) before the
API-versions bootstrap.
Plaintext is identical to Self::connect.
§Errors
Returns ClientError::Connect / ClientError::Timeout on the
TCP dial, ClientError::Tls or ClientError::Sasl if the TLS
handshake or the SASL exchange fails with no verdict from the peer,
ClientError::Authentication if the peer rejects authentication,
ClientError::InvalidConfig if the TLS settings do not build, or
ClientError::Io if the security policy is internally inconsistent
(e.g. a TLS protocol with no TLS config).
Sourcepub async fn from_stream(
stream: Box<dyn ClientDuplex>,
options: ConnectionOptions,
) -> Result<Self, ClientError>
pub async fn from_stream( stream: Box<dyn ClientDuplex>, options: ConnectionOptions, ) -> Result<Self, ClientError>
Build a Connection over a pre-established, optionally
pre-authenticated stream.
This method negotiates API versions over the stream and returns a
usable Connection. The broker’s InterBrokerClient integration
calls it: the TLS + SASL handshake runs before this call, so the
stream is already authenticated. From here on the connection’s normal
request / response framing applies.
§Errors
Returns an error when configuration is invalid, protocol encoding fails, the broker rejects the request, or transport I/O fails.
§Panics
Panics if synchronized client state is poisoned or a response violates an invariant established by protocol validation.
Sourcepub fn advertised_api_range(&self, api_key: i16) -> Option<(i16, i16)>
pub fn advertised_api_range(&self, api_key: i16) -> Option<(i16, i16)>
Return the peer-advertised version range for api_key.
Higher-level clients use this to distinguish an API that is absent from a listener’s surface from one whose advertised versions merely do not overlap their codec range.
Sourcepub async fn send<R: ProtocolRequest>(
&self,
req: R,
) -> Result<R::Response, ClientError>
pub async fn send<R: ProtocolRequest>( &self, req: R, ) -> Result<R::Response, ClientError>
Send a typed request and await the typed response.
This method negotiates the version from the broker-advertised table
that connect populated. It encodes and decodes the request and
response headers automatically.
§Errors
Returns ClientError::IncompatibleVersion if there is no mutually
supported version, ClientError::Disconnected if the I/O loop has
exited, or ClientError::Timeout if no response arrives in time.
Sourcepub async fn send_no_response<R: ProtocolRequest>(
&self,
req: R,
) -> Result<(), ClientError>
pub async fn send_no_response<R: ProtocolRequest>( &self, req: R, ) -> Result<(), ClientError>
Encode and enqueue a typed request that intentionally has no response.
Kafka Produce with acks=0 is the standard use case.
§Errors
Returns an error if version negotiation or encoding fails, or if the connection writer has stopped before accepting the frame.
Sourcepub async fn raw_request(
&self,
api_key: i16,
api_version: i16,
body: Bytes,
) -> Result<Bytes, ClientError>
pub async fn raw_request( &self, api_key: i16, api_version: i16, body: Bytes, ) -> Result<Bytes, ClientError>
Send a hand-framed request and await the raw response body.
This method bypasses the typed ProtocolRequest codegen path so
callers can speak Krabka-private APIs whose wire types live outside
krabka-protocol, for example the controller’s Raft RPCs at api keys
1000+.
This method always writes the header as RequestHeader v2 (flexible)
with an empty trailing tagged-fields byte. It assumes the response
uses ResponseHeader v1 (flexible): the I/O loop strips the 4-byte
correlation id, and this method strips the leading tagged-fields byte
before it returns. Callers receive the raw body bytes only.
body is the encoded request body, which is everything after the
request header, exactly as it should appear on the wire.
§Errors
Returns ClientError::Disconnected if the I/O loop has exited
or ClientError::Timeout if no response arrives within the
configured request timeout.
Sourcepub fn versions(&self) -> &ApiVersionTable
pub fn versions(&self) -> &ApiVersionTable
Negotiated API versions known to this connection.
Sourcepub fn in_flight(&self) -> usize
pub fn in_flight(&self) -> usize
The number of requests that wait for a response on this connection.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Whether the connection has closed: the peer closed it, an I/O error
ended it, it was idle for connections_max_idle, or Self::close
ran. A closed connection fails every request with Disconnected.
Sourcepub fn attach_metrics(&self, metrics: &NetworkMetrics)
pub fn attach_metrics(&self, metrics: &NetworkMetrics)
Count this connection in the client’s network metrics from now on. A connection counts in one set of metrics; a second call does nothing.
Trait Implementations§
Source§impl Clone for Connection
impl Clone for Connection
Source§fn clone(&self) -> Connection
fn clone(&self) -> Connection
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for Connection
impl !UnwindSafe for Connection
impl Freeze for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnsafeUnpin for Connection
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);