librdkafka
The Apache Kafka C/C++ client library
RdKafka::Message Class Referenceabstract

Message object. More...

#include <rdkafkacpp.h>

Public Types

enum  Status {
  MSG_STATUS_NOT_PERSISTED = 0 ,
  MSG_STATUS_POSSIBLY_PERSISTED = 1 ,
  MSG_STATUS_PERSISTED = 2
}
 Message persistence status can be used by the application to find out if a produced message was persisted in the topic log. More...
 

Public Member Functions

virtual std::string errstr () const =0
 Accessor functions*. More...
 
virtual ErrorCode err () const =0
 
virtual Topictopic () const =0
 
virtual std::string topic_name () const =0
 
virtual int32_t partition () const =0
 
virtual void * payload () const =0
 
virtual size_t len () const =0
 
virtual const std::string * key () const =0
 
virtual const void * key_pointer () const =0
 
virtual size_t key_len () const =0
 
virtual int64_t offset () const =0
 
virtual MessageTimestamp timestamp () const =0
 
virtual void * msg_opaque () const =0
 
virtual int64_t latency () const =0
 
virtual struct rd_kafka_message_s * c_ptr ()=0
 Returns the underlying librdkafka C rd_kafka_message_t handle. More...
 
virtual Status status () const =0
 Returns the message's persistence status in the topic log.
 
virtual RdKafka::Headersheaders ()=0
 
virtual RdKafka::Headersheaders (RdKafka::ErrorCode *err)=0
 
virtual int32_t broker_id () const =0
 

Detailed Description

Message object.

This object represents either a single consumed or produced message, or an event (err() is set).

An application must check RdKafka::Message::err() to see if the object is a proper message (error is RdKafka::ERR_NO_ERROR) or a an error event.

Member Enumeration Documentation

◆ Status

Message persistence status can be used by the application to find out if a produced message was persisted in the topic log.

Enumerator
MSG_STATUS_NOT_PERSISTED 

Message was never transmitted to the broker, or failed with an error indicating it was not written to the log. Application retry risks ordering, but not duplication.

MSG_STATUS_POSSIBLY_PERSISTED 

Message was transmitted to broker, but no acknowledgement was received. Application retry risks ordering and duplication.

MSG_STATUS_PERSISTED 

Message was written to the log and fully acknowledged. No reason for application to retry. Note: this value should only be trusted with acks=all.

Member Function Documentation

◆ errstr()

virtual std::string RdKafka::Message::errstr ( ) const
pure virtual

Accessor functions*.

Remarks
Not all fields are present in all types of callbacks.
Returns
The error string if object represent an error event, else an empty string.

◆ err()

virtual ErrorCode RdKafka::Message::err ( ) const
pure virtual
Returns
The error code if object represents an error event, else 0.

◆ topic()

virtual Topic* RdKafka::Message::topic ( ) const
pure virtual
Returns
the RdKafka::Topic object for a message (if applicable), or NULL if a corresponding RdKafka::Topic object has not been explicitly created with RdKafka::Topic::create(). In this case use topic_name() instead.

◆ topic_name()

virtual std::string RdKafka::Message::topic_name ( ) const
pure virtual
Returns
Topic name (if applicable, else empty string)

◆ partition()

virtual int32_t RdKafka::Message::partition ( ) const
pure virtual
Returns
Partition (if applicable)

◆ payload()

virtual void* RdKafka::Message::payload ( ) const
pure virtual
Returns
Message payload (if applicable)

◆ len()

virtual size_t RdKafka::Message::len ( ) const
pure virtual
Returns
Message payload length (if applicable)

◆ key()

virtual const std::string* RdKafka::Message::key ( ) const
pure virtual
Returns
Message key as string (if applicable)

◆ key_pointer()

virtual const void* RdKafka::Message::key_pointer ( ) const
pure virtual
Returns
Message key as void pointer (if applicable)

◆ key_len()

virtual size_t RdKafka::Message::key_len ( ) const
pure virtual
Returns
Message key's binary length (if applicable)

◆ offset()

virtual int64_t RdKafka::Message::offset ( ) const
pure virtual
Returns
Message or error offset (if applicable)

◆ timestamp()

virtual MessageTimestamp RdKafka::Message::timestamp ( ) const
pure virtual
Returns
Message timestamp (if applicable)

◆ msg_opaque()

virtual void* RdKafka::Message::msg_opaque ( ) const
pure virtual
Returns
The msg_opaque as provided to RdKafka::Producer::produce()

◆ latency()

virtual int64_t RdKafka::Message::latency ( ) const
pure virtual
Returns
the latency in microseconds for a produced message measured from the produce() call, or -1 if latency is not available.

◆ c_ptr()

virtual struct rd_kafka_message_s* RdKafka::Message::c_ptr ( )
pure virtual

Returns the underlying librdkafka C rd_kafka_message_t handle.

Warning
Calling the C API on this handle is not recommended and there is no official support for it, but for cases where the C++ API does not provide the underlying functionality this C handle can be used to interact directly with the core librdkafka API.
Remarks
The lifetime of the returned pointer is the same as the Message object this method is called on.
Include <rdkafka/rdkafka.h> prior to including <rdkafka/rdkafkacpp.h>
Returns
rd_kafka_message_t*

◆ headers() [1/2]

virtual RdKafka::Headers* RdKafka::Message::headers ( )
pure virtual
Returns
the Headers instance for this Message, or NULL if there are no headers.
Remarks
The lifetime of the Headers are the same as the Message.

◆ headers() [2/2]

virtual RdKafka::Headers* RdKafka::Message::headers ( RdKafka::ErrorCode err)
pure virtual
Returns
the Headers instance for this Message (if applicable). If NULL is returned the reason is given in err, which is either ERR__NOENT if there were no headers, or another error code if header parsing failed.
Remarks
The lifetime of the Headers are the same as the Message.

◆ broker_id()

virtual int32_t RdKafka::Message::broker_id ( ) const
pure virtual
Returns
the broker id of the broker the message was produced to or fetched from, or -1 if not known/applicable.

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