Struct kafka::consumer::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

A Kafka Consumer builder easing the process of setting up various configuration settings.

Implementations§

source§

impl Builder

source

pub fn with_group(self, group: String) -> Builder

Specifies the group on whose behalf to maintain consumed message offsets.

The group is allowed to be the empty string, in which case the resulting consumer will be group-less.

source

pub fn with_topic(self, topic: String) -> Builder

Specifies a topic to consume. All of the available partitions of the identified topic will be consumed unless overridden later using with_topic_partitions.

This method may be called multiple times to assign the consumer multiple topics.

This method or with_topic_partitions must be called at least once, to assign a topic to the consumer.

source

pub fn with_topic_partitions(self, topic: String, partitions: &[i32]) -> Builder

Explicitly specifies topic partitions to consume. Only the specified partitions for the identified topic will be consumed unless overridden later using with_topic.

This method may be called multiple times to subscribe to multiple topics.

This method or with_topic must be called at least once, to assign a topic to the consumer.

source

pub fn with_security(self, sec: SecurityConfig) -> Builder

Specifies the security config to use. See KafkaClient::new_secure for more info.

source

pub fn with_fallback_offset(self, fallback_offset: FetchOffset) -> Builder

Specifies the offset to use when none was committed for the underlying group yet or the consumer has no group configured.

Running the underlying group for the first time against a topic or running the consumer without a group results in the question where to start reading from the topic, since it might already contain a lot of messages. Common strategies are starting at the earliest available message (thereby consuming whatever is currently in the topic) or at the latest one (thereby staring to consume only newly arriving messages.) The “fallback offset” here corresponds to time in KafkaClient::fetch_offsets.

source

pub fn with_fetch_max_wait_time(self, max_wait_time: Duration) -> Builder

See KafkaClient::set_fetch_max_wait_time

source

pub fn with_fetch_min_bytes(self, min_bytes: i32) -> Builder

See KafkaClient::set_fetch_min_bytes

source

pub fn with_fetch_max_bytes_per_partition( self, max_bytes_per_partition: i32 ) -> Builder

See KafkaClient::set_fetch_max_bytes_per_partition

source

pub fn with_fetch_crc_validation(self, validate_crc: bool) -> Builder

See KafkaClient::set_fetch_crc_validation

source

pub fn with_offset_storage(self, storage: Option<GroupOffsetStorage>) -> Builder

See KafkaClient::set_group_offset_storage

source

pub fn with_retry_max_bytes_limit(self, limit: i32) -> Builder

Specifies the upper bound of data bytes to allow fetching from a kafka partition when retrying a fetch request due to a too big message in the partition.

By default, this consumer will fetch up to KafkaClient::fetch_max_bytes_per_partition data from each partition. However, when it discovers that there are messages in an underlying partition which could not be delivered, the request to that partition might be retried a few times with an increased fetch_max_bytes_per_partition. The value specified here defines a limit to this increment.

A value smaller than the KafkaClient::fetch_max_bytes_per_partition, e.g. zero, will disable the retry feature of this consumer. The default value for this setting is DEFAULT_RETRY_MAX_BYTES_LIMIT.

Note: if the consumed topic partitions are known to host large messages it is much more efficient to set KafkaClient::fetch_max_bytes_per_partition appropriately instead of relying on the limit specified here. This limit is just an upper bound for already additional retry requests.

source

pub fn with_connection_idle_timeout(self, timeout: Duration) -> Self

Specifies the timeout for idle connections. See KafkaClient::set_connection_idle_timeout.

source

pub fn with_client_id(self, client_id: String) -> Self

Specifies a client_id to be sent along every request to Kafka brokers. See KafkaClient::set_client_id.

source

pub fn create(self) -> Result<Consumer>

Finally creates/builds a new consumer based on the so far supplied settings.

Fails with the NoTopicsAssigned error, if neither with_topic nor with_topic_partitions have been called to assign at least one topic for consumption.

Trait Implementations§

source§

impl Debug for Builder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

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

§

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