Struct rdkafka::message::BorrowedMessage
[−]
[src]
pub struct BorrowedMessage<'a> { /* fields omitted */ }
A zero-copy Kafka message.
The content of the message is stored in the receiving buffer of the consumer or the producer. As
such, BorrowedMessage
cannot outlive the consumer or producer it belongs to.
Consumers
BorrowedMessage
s coming from consumers are removed from the consumer buffer once they are
dropped. Holding references to too many messages will cause the memory of the consumer to fill
up and the consumer to block until some of the BorrowedMessage
s are dropped.
Conversion to owned
To transform a BorrowedMessage
into a OwnedMessage
, use the detach
method.
Methods
impl<'a> BorrowedMessage<'a>
[src]
unsafe fn from_consumer<C>(
ptr: *mut RDKafkaMessage,
_consumer: &'a C
) -> KafkaResult<BorrowedMessage<'a>>
[src]
ptr: *mut RDKafkaMessage,
_consumer: &'a C
) -> KafkaResult<BorrowedMessage<'a>>
Creates a new BorrowedMessage
that wraps the native Kafka message pointer returned by a
consumer. The lifetime of the message will be bound to the lifetime of the consumer passed
as parameter. This method should only be used with messages coming from consumers. If the
message contains an error, only the error is returned and the message structure is freed.
unsafe fn from_dr_callback<O>(
ptr: *mut RDKafkaMessage,
_owner: &'a O
) -> DeliveryResult<'a>
[src]
ptr: *mut RDKafkaMessage,
_owner: &'a O
) -> DeliveryResult<'a>
Creates a new BorrowedMessage
that wraps the native Kafka message pointer returned by the
delivery callback of a producer. The lifetime of the message will be bound to the lifetime
of the reference passed as parameter. This method should only be used with messages coming
from the delivery callback. The message will not be freed in any circumstance.
fn ptr(&self) -> *mut RDKafkaMessage
[src]
Returns a pointer to the RDKafkaMessage.
fn topic_ptr(&self) -> *mut RDKafkaTopic
[src]
Returns a pointer to the message's RDKafkaTopic
fn key_len(&self) -> usize
[src]
Returns the length of the key field of the message.
fn payload_len(&self) -> usize
[src]
Returns the length of the payload field of the message.
fn detach(&self) -> OwnedMessage
[src]
Clones the content of the BorrowedMessage
and returns an OwnedMessage
, that can
outlive the consumer. This operation requires memory allocation and can be expensive.
Trait Implementations
impl<'a> Debug for BorrowedMessage<'a>
[src]
impl<'a> Message for BorrowedMessage<'a>
[src]
fn key(&self) -> Option<&[u8]>
[src]
Returns the key of the message, or None if there is no key.
fn payload(&self) -> Option<&[u8]>
[src]
Returns the payload of the message, or None if there is no payload.
fn topic(&self) -> &str
[src]
Returns the source topic of the message.
fn partition(&self) -> i32
[src]
Returns the partition number where the message is stored.
fn offset(&self) -> i64
[src]
Returns the offset of the message.
fn timestamp(&self) -> Timestamp
[src]
Returns the message timestamp for a consumed message if available.
fn payload_view<P: ?Sized + FromBytes>(&self) -> Option<Result<&P, P::Error>>
[src]
Converts the raw bytes of the payload to a reference of the specified type, that points to the same data inside the message and without performing any memory allocation Read more
fn key_view<K: ?Sized + FromBytes>(&self) -> Option<Result<&K, K::Error>>
[src]
Converts the raw bytes of the key to a reference of the specified type, that points to the same data inside the message and without performing any memory allocation Read more