librdkafka
The Apache Kafka C/C++ client library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RdKafka::Consumer Class Referenceabstract

Simple Consumer (legacy) More...

#include <rdkafkacpp.h>

Inheritance diagram for RdKafka::Consumer:
Collaboration diagram for RdKafka::Consumer:

Public Member Functions

virtual ErrorCode start (Topic *topic, int32_t partition, int64_t offset)=0
 Start consuming messages for topic and partition at offset offset which may either be a proper offset (0..N) or one of the the special offsets: OFFSET_BEGINNING or OFFSET_END. More...
 
virtual ErrorCode start (Topic *topic, int32_t partition, int64_t offset, Queue *queue)=0
 Start consuming messages for topic and partition on queue queue. More...
 
virtual ErrorCode stop (Topic *topic, int32_t partition)=0
 Stop consuming messages for topic and partition, purging all messages currently in the local queue. More...
 
virtual Messageconsume (Topic *topic, int32_t partition, int timeout_ms)=0
 Consume a single message from topic and partition. More...
 
virtual Messageconsume (Queue *queue, int timeout_ms)=0
 Consume a single message from the specified queue. More...
 
virtual int consume_callback (Topic *topic, int32_t partition, int timeout_ms, ConsumeCb *consume_cb, void *opaque)=0
 Consumes messages from topic and partition, calling the provided callback for each consumed messsage. More...
 
virtual int consume_callback (Queue *queue, int timeout_ms, RdKafka::ConsumeCb *consume_cb, void *opaque)=0
 Consumes messages from queue, calling the provided callback for each consumed messsage. More...
 
- Public Member Functions inherited from RdKafka::Handle
virtual const std::string name () const =0
 
virtual const std::string memberid () const =0
 Returns the client's broker-assigned group member id. More...
 
virtual int poll (int timeout_ms)=0
 Polls the provided kafka handle for events. More...
 
virtual int outq_len ()=0
 Returns the current out queue length. More...
 
virtual ErrorCode metadata (bool all_topics, const Topic *only_rkt, Metadata **metadatap, int timeout_ms)=0
 Request Metadata from broker. More...
 

Static Public Member Functions

static Consumercreate (Conf *conf, std::string &errstr)
 Creates a new Kafka consumer handle. More...
 
static int64_t OffsetTail (int64_t offset)
 Converts an offset into the logical offset from the tail of a topic. More...
 

Detailed Description

Simple Consumer (legacy)

A simple non-balanced, non-group-aware, consumer.

Member Function Documentation

static Consumer* RdKafka::Consumer::create ( Conf conf,
std::string &  errstr 
)
static

Creates a new Kafka consumer handle.

conf is an optional object that will be used instead of the default configuration. The conf object is reusable after this call.

Returns
the new handle on success or NULL on error in which case errstr is set to a human readable error message.
virtual ErrorCode RdKafka::Consumer::start ( Topic topic,
int32_t  partition,
int64_t  offset 
)
pure virtual

Start consuming messages for topic and partition at offset offset which may either be a proper offset (0..N) or one of the the special offsets: OFFSET_BEGINNING or OFFSET_END.

rdkafka will attempt to keep queued.min.messages (config property) messages in the local queue by repeatedly fetching batches of messages from the broker until the threshold is reached.

The application shall use one of the ..->consume*() functions to consume messages from the local queue, each kafka message being represented as a RdKafka::Message * object.

..->start() must not be called multiple times for the same topic and partition without stopping consumption first with ..->stop().

Returns
an ErrorCode to indicate success or failure.
virtual ErrorCode RdKafka::Consumer::start ( Topic topic,
int32_t  partition,
int64_t  offset,
Queue queue 
)
pure virtual

Start consuming messages for topic and partition on queue queue.

See also
RdKafka::Consumer::start()
virtual ErrorCode RdKafka::Consumer::stop ( Topic topic,
int32_t  partition 
)
pure virtual

Stop consuming messages for topic and partition, purging all messages currently in the local queue.

The application needs to be stop all consumers before destroying the Consumer handle.

Returns
an ErrorCode to indicate success or failure.
virtual Message* RdKafka::Consumer::consume ( Topic topic,
int32_t  partition,
int  timeout_ms 
)
pure virtual

Consume a single message from topic and partition.

timeout_ms is maximum amount of time to wait for a message to be received. Consumer must have been previously started with ..->start().

Returns
a Message object, the application needs to check if message is an error or a proper message RdKafka::Message::err() and checking for ERR_NO_ERROR.

The message object must be destroyed when the application is done with it.

Errors (in RdKafka::Message::err()):

  • ERR__TIMED_OUT - timeout_ms was reached with no new messages fetched.
  • ERR__PARTITION_EOF - End of partition reached, not an error.
virtual Message* RdKafka::Consumer::consume ( Queue queue,
int  timeout_ms 
)
pure virtual

Consume a single message from the specified queue.

timeout_ms is maximum amount of time to wait for a message to be received. Consumer must have been previously started on the queue with ..->start().

Returns
a Message object, the application needs to check if message is an error or a proper message Message->err() and checking for ERR_NO_ERROR.

The message object must be destroyed when the application is done with it.

Errors (in RdKafka::Message::err()):

  • ERR__TIMED_OUT - timeout_ms was reached with no new messages fetched

Note that Message->topic() may be nullptr after certain kinds of errors, so applications should check that it isn't null before dereferencing it.

virtual int RdKafka::Consumer::consume_callback ( Topic topic,
int32_t  partition,
int  timeout_ms,
ConsumeCb consume_cb,
void *  opaque 
)
pure virtual

Consumes messages from topic and partition, calling the provided callback for each consumed messsage.

consume_callback() provides higher throughput performance than consume().

timeout_ms is the maximum amount of time to wait for one or more messages to arrive.

The provided consume_cb instance has its consume_cb function called for every message received.

The opaque argument is passed to the consume_cb as opaque.

Returns
the number of messages processed or -1 on error.
See also
RdKafka::Consumer::consume()
virtual int RdKafka::Consumer::consume_callback ( Queue queue,
int  timeout_ms,
RdKafka::ConsumeCb consume_cb,
void *  opaque 
)
pure virtual

Consumes messages from queue, calling the provided callback for each consumed messsage.

See also
RdKafka::Consumer::consume_callback()
static int64_t RdKafka::Consumer::OffsetTail ( int64_t  offset)
static

Converts an offset into the logical offset from the tail of a topic.

offset is the (positive) number of items from the end.


The documentation for this class was generated from the following file: