pub struct BaseConsumer<C = DefaultConsumerContext> where
    C: ConsumerContext
{ /* private fields */ }
Expand description

A low-level consumer that requires manual polling.

This consumer must be periodically polled to make progress on rebalancing, callbacks and to receive messages.

Implementations

Polls the consumer for new messages.

It won’t block for more than the specified timeout. Use zero Duration for non-blocking call. With no timeout it blocks until an event is received.

This method should be called at regular intervals, even if no message is expected, to serve any queued callbacks waiting to be called. This is especially important for automatic consumer rebalance, as the rebalance function will be executed by the thread calling the poll() function.

Lifetime

The returned message lives in the memory of the consumer and cannot outlive it.

Returns an iterator over the available messages.

It repeatedly calls poll with no timeout.

Note that it’s also possible to iterate over the consumer directly.

Examples

All these are equivalent and will receive messages without timing out.

loop {
  let message = consumer.poll(None);
  // Handle the message
}
for message in consumer.iter() {
  // Handle the message
}
for message in &consumer {
  // Handle the message
}

Splits messages for the specified partition into their own queue.

If the topic or partition is invalid, returns None.

After calling this method, newly-fetched messages for the specified partition will be returned via PartitionQueue::poll rather than BaseConsumer::poll. Note that there may be buffered messages for the specified partition that will continue to be returned by BaseConsumer::poll. For best results, call split_partition_queue before the first call to BaseConsumer::poll.

You must continue to call BaseConsumer::poll, even if no messages are expected, to serve callbacks.

Note that calling Consumer::assign will deactivate any existing partition queues. You will need to call this method for every partition that should be split after every call to assign.

Beware that this method is implemented for &Arc<Self>, not &self. You will need to wrap your consumer in an Arc in order to call this method. This design permits moving the partition queue to another thread while ensuring the partition queue does not outlive the consumer.

Trait Implementations

Returns the Client underlying this consumer.

Returns the current consumer group metadata associated with the consumer. Read more

Subscribes the consumer to a list of topics.

Unsubscribes the current subscription list.

Manually assigns topics and partitions to the consumer. If used, automatic consumer rebalance won’t be activated. Read more

Seeks to offset for the specified topic and partition. After a successful call to seek, the next poll of the consumer will return the message with offset. Read more

Commits the offset of the specified message. The commit can be sync (blocking), or async. Notice that when a specific offset is committed, all the previous offsets are considered committed as well. Use this method only if you are processing messages in order. Read more

Commits the current consumer state. Notice that if the consumer fails after a message has been received, but before the message has been processed by the user code, this might lead to data loss. Check the “at-least-once delivery” section in the readme for more information. Read more

Commit the provided message. Note that this will also automatically commit every message with lower offset within the same partition. Read more

Stores offset to be used on the next (auto)commit. When using this enable.auto.offset.store should be set to false in the config. Read more

Like Consumer::store_offset, but the offset to store is derived from the provided message. Read more

Store offsets to be used on the next (auto)commit. When using this enable.auto.offset.store should be set to false in the config. Read more

Returns the current topic subscription.

Returns the current partition assignment.

Retrieves the committed offsets for topics and partitions.

Retrieves the committed offsets for specified topics and partitions.

Looks up the offsets for this consumer’s partitions by timestamp.

Looks up the offsets for the specified partitions by timestamp.

Retrieve current positions (offsets) for topics and partitions.

Returns the metadata information for the specified topic, or for all topics in the cluster if no topic is specified. Read more

Returns the low and high watermarks for a specific topic and partition.

Returns the group membership information for the given group. If no group is specified, all groups will be returned. Read more

Pauses consumption for the provided list of partitions.

Resumes consumption for the provided list of partitions.

Reports the rebalance protocol in use.

Returns a reference to the ConsumerContext used to create this consumer. Read more

Executes the destructor for this type. Read more

Creates a client from a client configuration. The default client context will be used. Read more

Creates a new BaseConsumer starting from a ClientConfig.

Creates a client from a client configuration and a client context.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.