|
NAMEKafka::Connection - Object interface to connect to a kafka cluster.VERSIONThis documentation refers to "Kafka::Connection" version 0.8010 .SYNOPSISuse 5.010; use strict; use warnings; use Scalar::Util qw( blessed ); use Try::Tiny; # A simple example of Kafka::Connection usage: use Kafka::Connection; # connect to local cluster with the defaults my $connection; try { $connection = Kafka::Connection->new( host => 'localhost' ); } catch { if ( blessed( $_ ) && $_->isa( 'Kafka::Exception' ) ) { warn $_->message, "\n", $_->trace->as_string, "\n"; exit; } else { die $_; } }; # Closes the connection and cleans up undef $connection; DESCRIPTIONThe main features of the "Kafka::Connection" class are:
EXPORTThe following constants are available for export%RETRY_ON_ERRORS These are non-fatal errors, which when happen causes refreshing of meta-data from Kafka followed by another attempt to fetch data. CONSTRUCTOR"new"Creates "Kafka::Connection" object for interaction with Kafka cluster. Returns created "Kafka::Connection" object. "new()" takes arguments in key-value pairs. The following arguments are currently recognized:
METHODSThe following methods are defined for the "Kafka::Producer" class:"get_known_servers" Returns the list of known Kafka servers (in host:port format). "get_metadata( $topic )" If $topic is present, it must be a non-false string of non-zero length. If $topic is absent, this method returns metadata for all topics. Updates kafka cluster's metadata description and returns the hash reference to metadata, which can be schematically described as: { TopicName => { Partition => { 'Leader' => ..., 'Replicas' => [ ..., ], 'Isr' => [ ..., ], }, ..., }, ..., } Consult Kafka "Wire protocol" documentation for more details about metadata structure. "is_server_known( $server )" Returns true, if $server (host:port) is known in cluster. "is_server_alive( $server )" Returns true, if known $server (host:port) is accessible. Checks the accessibility of the server. "is_server_connected( $server )" Returns true, if successful connection is established with $server (host:port). "receive_response_to_request( $request, $compression_codec )"
WARNING:
"exists_topic_partition( $topic, $partition )" Returns true if the metadata contains information about specified combination of topic and partition. Otherwise returns false. "exists_topic_partition()" takes the following arguments:
"close_connection( $server )" Closes connection with $server (defined as host:port). "close" Closes connection with all known Kafka servers. "cluster_errors" Returns a reference to a hash. Each hash key is the identifier of the server (host:port), and the value is the last communication error with that server. An empty hash is returned if there were no communication errors. "nonfatal_errors" Returns a reference to an array of the last non-fatal errors. Maximum number of entries is set using "MaxLoggedErrors" parameter of constructor. A reference to the empty array is returned if there were no non-fatal errors or parameter "MaxLoggedErrors" is set to 0. "clear_nonfatals" Clears an array of the last non-fatal errors. A reference to the empty array is returned because there are no non-fatal errors now. DIAGNOSTICSWhen error is detected, an exception, represented by object of Kafka::Exception::Connection class, is thrown (see Kafka::Exceptions).code and a more descriptive message provide information about exception. Consult documentation of the Kafka::Exceptions for the list of all available methods. Here is the list of possible error messages that "Kafka::Connection" may produce:
Debug modeDebug output can be enabled by passing desired level via environment variable using one of the following ways:"PERL_KAFKA_DEBUG=1" - debug is enabled for the whole Kafka package. "PERL_KAFKA_DEBUG=Connection:1" - enable debug for "Kafka::Connection" only. "Kafka::Connection" prints to "STDERR" information about non-fatal errors, re-connection attempts and such when debug level is set to 1 or higher. SEE ALSOThe basic operation of the Kafka package modules:Kafka - constants and messages used by the Kafka package modules. Kafka::Connection - interface to connect to a Kafka cluster. Kafka::Producer - interface for producing client. Kafka::Consumer - interface for consuming client. Kafka::Message - interface to access Kafka message properties. Kafka::Int64 - functions to work with 64 bit elements of the protocol on 32 bit systems. Kafka::Protocol - functions to process messages in the Apache Kafka's Protocol. Kafka::IO - low-level interface for communication with Kafka server. Kafka::Exceptions - module designated to handle Kafka exceptions. Kafka::Internals - internal constants and functions used by several package modules. A wealth of detail about the Apache Kafka and the Kafka Protocol: Main page at <http://kafka.apache.org/> Kafka Protocol at <https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol> SOURCE CODEKafka package is hosted on GitHub: <https://github.com/TrackingSoft/Kafka>AUTHORSergey Gladkov, <sgladkov@trackingsoft.com>CONTRIBUTORSAlexander SoloveyJeremy Jordan Sergiy Zuban Vlad Marchenko COPYRIGHT AND LICENSECopyright (C) 2012-2013 by TrackingSoft LLC.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.
Visit the GSP FreeBSD Man Page Interface. |