class FetchResponse

Header File: <libkafka_asio/fetch_response.h>

Namespace: libkafka_asio

Implementation of the Kafka FetchResponse as described on the Kafka wiki. An object of this type will be given as response object to the handler function when invoking a fetch request.

Member Functions

begin

const_iterator begin() const

Creates and returns an iterator object that can be used for iterating over all received messages. This function returns the start iterator object.

// Assume the response is an argument of the request handler function
FetchResponse::OptionalType response;

// C++11 range-based for loop
for (auto message : *response)
{
    // Do something with the message...
}
// STL for_each: Call a function for each received Message
std::for_each(response->begin(), response->end(), &PrintMessage);
// 'traditional' iteration
FetchResponse::const_iterator iter = response->begin();
FetchResponse::const_iterator end_iter = response->end();
for (; iter != end_iter; ++iter)
{
    // Again, do something...
}

end

const_iterator end() const

End iterator (see start iterator description above). Similar to default construction of the const_iterator type.

topics

const Topics& topics() const

Returns a reference to the set of topics, messages have been received for.

Types

Topic

struct Topic {
    Partitions partitions;
}
  • partitions: Map of partitions of this topic for which message data has been received.

Partition

struct Partition {
    Int16       error_code;
    Int64       highwater_mark_offset;
    MessageSet  messages;
}
  • error_code: Kafka error for this topic partition.
  • highwater_mark_offset: Offset at the end of the log for this partition on the server.
  • messages: The fetched messages.

Topics

typedef std::map<String, Topic> Topics

Map that associates a Topic object to the topic name.

Partitions

typedef std::map<Int32, Partition> Partitions

Map that associates a Partition object to the partition id.

const_iterator

typedef defail::FetchResponseIterator<TopicVector> const_iterator

Constant iterator type, used for iterating over all messages of a fetch response object. See FetchResponseIterator class template for details.

OptionalType

typedef boost::optional<FetchResponse> OptionalType

A fetch response object wrapped using Boost optional. Such an object will be used for fetch request handler functions.