View on
Sergey Gladkov > Kafka-0.12 > Kafka::Message



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.12   Source   Latest Release: Kafka-1.07


Kafka::Message - object interface to the Kafka message properties


This documentation refers to Kafka::Message version 0.12


The Kafka Consumer response has an ARRAY reference type. For the fetch response array has the class name Kafka::Message elements.

    # Consuming messages
    my $messages = $consumer->fetch(
        "test",             # topic
        0,                  # partition
        0,                  # offset
        DEFAULT_MAX_SIZE    # Maximum size of MESSAGE(s) to receive
    if ( $messages )
        foreach my $message ( @$messages )
            if( $message->valid )
                print "payload    : ", $message->payload,       "\n";
                print "offset     : ", $message->offset,        "\n";
                print "next_offset: ", $message->next_offset,   "\n";
                print "error      : ", $message->error,         "\n";


Kafka message API is implemented by Kafka::Message class.

The Kafka::Message module in Kafka package provides an object oriented access to the message properties. Reference to an array of objects of class Kafka::Message returned by the fetch method of the Consumer client. Package Kafka Kafka::Message class is not otherwise used.

The main features of the Kafka::Message class are:


new ( \%arg )

Creates a Kafka::Message, which is a newly created message object. new() takes an argument, this argument is a HASH reference with the currently used methods entries.

Returns the created message as a Kafka::Message object, or error will cause the program to halt (confess) if the argument is not a valid HASH reference.


The following methods are available for each Kafka::Message object and are specific to that object and the method calls invoked on it.

The available methods for objects of the Kafka::Message class are:


A simple message received from the Apache Kafka server.


A message entry is valid if the CRC32 of the message payload matches to the CRC stored with the message.


A description of the message inconsistence (currently only for when message is not valid or is compressed).


The offset beginning of the message in the Apache Kafka server.


The offset beginning of the next message in the Apache Kafka server.


Kafka::Message is not a user module and any constructor error is FATAL. FATAL errors will cause the program to halt (confess), since the problem is so severe that it would be dangerous to continue. (This can always be trapped with eval. Under the circumstances, dying is the best thing to do).

Mismatch argument

This means that you didn't give the right argument to a new constructor, i.e. not a raw and unblessed HASH reference, or a HASH key doesn't have valid methods name, or not defined value.


The basic operation of the Kafka package modules:

Kafka - constants and messages used by the Kafka package modules

Kafka::IO - object interface to socket communications with the Apache Kafka server

Kafka::Producer - object interface to the producer client

Kafka::Consumer - object interface to the consumer client

Kafka::Message - object interface to the Kafka message properties

Kafka::Protocol - functions to process messages in the Apache Kafka's wire format

Kafka::Int64 - functions to work with 64 bit elements of the protocol on 32 bit systems

Kafka::Mock - object interface to the TCP mock server for testing

A wealth of detail about the Apache Kafka and Wire Format:

Main page at

Wire Format at

Writing a Driver for Kafka at


Sergey Gladkov, <>


Alexander Solovey

Jeremy Jordan

Vlad Marchenko


Copyright (C) 2012-2013 by TrackingSoft LLC. All rights reserved.

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic at

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

syntax highlighting: