The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

VERSION

This documentation refers to Kafka::Message version 0.12

SYNOPSIS

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";
            }
            else
            {
                print "error      : ", $message->error,         "\n";
            }
        }
    }

DESCRIPTION

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:

CONSTRUCTOR

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.

METHODS

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:

payload

A simple message received from the Apache Kafka server.

valid

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

error

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

offset

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

next_offset

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

DIAGNOSTICS

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.

SEE ALSO

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 http://incubator.apache.org/kafka/

Wire Format at http://cwiki.apache.org/confluence/display/KAFKA/Wire+Format/

Writing a Driver for Kafka at http://cwiki.apache.org/confluence/display/KAFKA/Writing+a+Driver+for+Kafka

AUTHOR

Sergey Gladkov, <sgladkov@trackingsoft.com>

CONTRIBUTORS

Alexander Solovey

Jeremy Jordan

Vlad Marchenko

COPYRIGHT AND LICENSE

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 http://dev.perl.org/licenses/artistic.html.

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.