| 1 | package Kafka; | ||
| 2 | |||
| 3 | # Kafka allows you to produce and consume messages using | ||
| 4 | # the Apache Kafka distributed publish/subscribe messaging service. | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Kafka - Apache Kafka interface for Perl. | ||
| 9 | |||
| 10 | =head1 VERSION | ||
| 11 | |||
| 12 | This documentation refers to C<Kafka> package version 1.07 . | ||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | use 5.010; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | our $VERSION = '1.07'; | ||
| 25 | |||
| 26 | use Exporter qw( | ||
| 27 | import | ||
| 28 | ); | ||
| 29 | |||
| 30 | our @EXPORT_OK = qw( | ||
| 31 | $BITS64 | ||
| 32 | $BLOCK_UNTIL_IS_COMMITTED | ||
| 33 | $COMPRESSION_GZIP | ||
| 34 | $COMPRESSION_NONE | ||
| 35 | $COMPRESSION_SNAPPY | ||
| 36 | $COMPRESSION_LZ4 | ||
| 37 | $DEFAULT_MAX_BYTES | ||
| 38 | $DEFAULT_MAX_NUMBER_OF_OFFSETS | ||
| 39 | $DEFAULT_MAX_WAIT_TIME | ||
| 40 | %ERROR | ||
| 41 | $ERROR_BROKER_NOT_AVAILABLE | ||
| 42 | $ERROR_CANNOT_BIND | ||
| 43 | $ERROR_CANNOT_GET_METADATA | ||
| 44 | $ERROR_CANNOT_RECV | ||
| 45 | $ERROR_CANNOT_SEND | ||
| 46 | $ERROR_COMPRESSION | ||
| 47 | $ERROR_CONSUMER_COORDINATOR_NOT_AVAILABLE_CODE | ||
| 48 | $ERROR_GROUP_COORDINATOR_NOT_AVAILABLE | ||
| 49 | $ERROR_GROUP_COORDINATOR_NOT_AVAILABLE_CODE | ||
| 50 | $ERROR_INVALID_MESSAGE | ||
| 51 | $ERROR_CORRUPT_MESSAGE | ||
| 52 | $ERROR_INVALID_FETCH_SIZE | ||
| 53 | $ERROR_INVALID_MESSAGE_SIZE | ||
| 54 | $ERROR_LEADER_NOT_AVAILABLE | ||
| 55 | $ERROR_LEADER_NOT_FOUND | ||
| 56 | $ERROR_GROUP_COORDINATOR_NOT_FOUND | ||
| 57 | $ERROR_LOAD_IN_PROGRESS_CODE | ||
| 58 | $ERROR_GROUP_LOAD_IN_PROGRESS | ||
| 59 | $ERROR_GROUP_LOAD_IN_PROGRESS_CODE | ||
| 60 | $ERROR_MESSAGE_SIZE_TOO_LARGE | ||
| 61 | $ERROR_MESSAGE_TOO_LARGE | ||
| 62 | $ERROR_NETWORK_EXCEPTION | ||
| 63 | $ERROR_METADATA_ATTRIBUTES | ||
| 64 | $ERROR_MISMATCH_ARGUMENT | ||
| 65 | $ERROR_MISMATCH_CORRELATIONID | ||
| 66 | $ERROR_NO_CONNECTION | ||
| 67 | $ERROR_NO_ERROR | ||
| 68 | $ERROR_NO_KNOWN_BROKERS | ||
| 69 | $ERROR_NOT_BINARY_STRING | ||
| 70 | $ERROR_NOT_LEADER_FOR_PARTITION | ||
| 71 | $ERROR_NOT_COORDINATOR_FOR_CONSUMER_CODE | ||
| 72 | $ERROR_NOT_COORDINATOR_FOR_GROUP | ||
| 73 | $ERROR_NOT_COORDINATOR_FOR_GROUP_CODE | ||
| 74 | $ERROR_OFFSET_METADATA_TOO_LARGE | ||
| 75 | $ERROR_OFFSET_METADATA_TOO_LARGE_CODE | ||
| 76 | $ERROR_OFFSET_OUT_OF_RANGE | ||
| 77 | $ERROR_PARTITION_DOES_NOT_MATCH | ||
| 78 | $ERROR_REPLICA_NOT_AVAILABLE | ||
| 79 | $ERROR_REQUEST_OR_RESPONSE | ||
| 80 | $ERROR_REQUEST_TIMED_OUT | ||
| 81 | $ERROR_RESPONSEMESSAGE_NOT_RECEIVED | ||
| 82 | $ERROR_INCOMPATIBLE_HOST_IP_VERSION | ||
| 83 | $ERROR_SEND_NO_ACK | ||
| 84 | $ERROR_STALE_CONTROLLER_EPOCH | ||
| 85 | $ERROR_STALE_CONTROLLER_EPOCH_CODE | ||
| 86 | $ERROR_TOPIC_DOES_NOT_MATCH | ||
| 87 | $ERROR_UNKNOWN | ||
| 88 | $ERROR_UNKNOWN_APIKEY | ||
| 89 | $ERROR_UNKNOWN_TOPIC_OR_PARTITION | ||
| 90 | $ERROR_INVALID_TOPIC_CODE | ||
| 91 | $ERROR_INVALID_TOPIC_EXCEPTION | ||
| 92 | $ERROR_RECORD_LIST_TOO_LARGE | ||
| 93 | $ERROR_RECORD_LIST_TOO_LARGE_CODE | ||
| 94 | $ERROR_NOT_ENOUGH_REPLICAS | ||
| 95 | $ERROR_NOT_ENOUGH_REPLICAS_CODE | ||
| 96 | $ERROR_NOT_ENOUGH_REPLICAS_AFTER_APPEND | ||
| 97 | $ERROR_NOT_ENOUGH_REPLICAS_AFTER_APPEND_CODE | ||
| 98 | $ERROR_INVALID_REQUIRED_ACKS | ||
| 99 | $ERROR_INVALID_REQUIRED_ACKS_CODE | ||
| 100 | $ERROR_ILLEGAL_GENERATION | ||
| 101 | $ERROR_ILLEGAL_GENERATION_CODE | ||
| 102 | $ERROR_INCONSISTENT_GROUP_PROTOCOL | ||
| 103 | $ERROR_INCONSISTENT_GROUP_PROTOCOL_CODE | ||
| 104 | $ERROR_INVALID_GROUP_ID | ||
| 105 | $ERROR_INVALID_GROUP_ID_CODE | ||
| 106 | $ERROR_UNKNOWN_MEMBER_ID | ||
| 107 | $ERROR_UNKNOWN_MEMBER_ID_CODE | ||
| 108 | $ERROR_INVALID_SESSION_TIMEOUT | ||
| 109 | $ERROR_INVALID_SESSION_TIMEOUT_CODE | ||
| 110 | $ERROR_REBALANCE_IN_PROGRESS | ||
| 111 | $ERROR_REBALANCE_IN_PROGRESS_CODE | ||
| 112 | $ERROR_INVALID_COMMIT_OFFSET_SIZE | ||
| 113 | $ERROR_INVALID_COMMIT_OFFSET_SIZE_CODE | ||
| 114 | $ERROR_TOPIC_AUTHORIZATION_FAILED | ||
| 115 | $ERROR_TOPIC_AUTHORIZATION_FAILED_CODE | ||
| 116 | $ERROR_GROUP_AUTHORIZATION_FAILED | ||
| 117 | $ERROR_GROUP_AUTHORIZATION_FAILED_CODE | ||
| 118 | $ERROR_CLUSTER_AUTHORIZATION_FAILED | ||
| 119 | $ERROR_CLUSTER_AUTHORIZATION_FAILED_CODE | ||
| 120 | $ERROR_INVALID_TIMESTAMP | ||
| 121 | $ERROR_UNSUPPORTED_SASL_MECHANISM | ||
| 122 | $ERROR_ILLEGAL_SASL_STATE | ||
| 123 | $ERROR_UNSUPPORTED_VERSION | ||
| 124 | $IP_V4 | ||
| 125 | $IP_V6 | ||
| 126 | $KAFKA_SERVER_PORT | ||
| 127 | $MESSAGE_SIZE_OVERHEAD | ||
| 128 | $MIN_BYTES_RESPOND_HAS_DATA | ||
| 129 | $MIN_BYTES_RESPOND_IMMEDIATELY | ||
| 130 | $NOT_SEND_ANY_RESPONSE | ||
| 131 | $RECEIVE_EARLIEST_OFFSET | ||
| 132 | $RECEIVE_EARLIEST_OFFSETS | ||
| 133 | $RECEIVE_LATEST_OFFSET | ||
| 134 | $RECEIVE_LATEST_OFFSETS | ||
| 135 | $REQUEST_TIMEOUT | ||
| 136 | $RETRY_BACKOFF | ||
| 137 | $SEND_MAX_ATTEMPTS | ||
| 138 | $WAIT_WRITTEN_TO_LOCAL_LOG | ||
| 139 | ); | ||
| 140 | |||
| 141 | |||
| 142 | |||
| 143 | use Config; | ||
| 144 | use Const::Fast; | ||
| 145 | |||
| 146 | |||
| 147 | |||
| 148 | =head1 SYNOPSIS | ||
| 149 | |||
| 150 | use 5.010; | ||
| 151 | use strict; | ||
| 152 | use warnings; | ||
| 153 | |||
| 154 | use Scalar::Util qw( | ||
| 155 | blessed | ||
| 156 | ); | ||
| 157 | use Try::Tiny; | ||
| 158 | |||
| 159 | use Kafka qw( | ||
| 160 | $BITS64 | ||
| 161 | ); | ||
| 162 | use Kafka::Connection; | ||
| 163 | use Kafka::Producer; | ||
| 164 | use Kafka::Consumer; | ||
| 165 | |||
| 166 | # A simple example of Kafka usage | ||
| 167 | |||
| 168 | # common information | ||
| 169 | say 'This is Kafka package ', $Kafka::VERSION; | ||
| 170 | say 'You have a ', $BITS64 ? '64' : '32', ' bit system'; | ||
| 171 | |||
| 172 | my ( $connection, $producer, $consumer ); | ||
| 173 | try { | ||
| 174 | |||
| 175 | #-- Connect to local cluster | ||
| 176 | $connection = Kafka::Connection->new( host => 'localhost' ); | ||
| 177 | #-- Producer | ||
| 178 | $producer = Kafka::Producer->new( Connection => $connection ); | ||
| 179 | #-- Consumer | ||
| 180 | $consumer = Kafka::Consumer->new( Connection => $connection ); | ||
| 181 | |||
| 182 | } catch { | ||
| 183 | my $error = $_; | ||
| 184 | if ( blessed( $error ) && $error->isa( 'Kafka::Exception' ) ) { | ||
| 185 | warn 'Error: (', $error->code, ') ', $error->message, "\n"; | ||
| 186 | exit; | ||
| 187 | } else { | ||
| 188 | die $error; | ||
| 189 | } | ||
| 190 | }; | ||
| 191 | |||
| 192 | # cleaning up | ||
| 193 | undef $consumer; | ||
| 194 | undef $producer; | ||
| 195 | $connection->close; | ||
| 196 | undef $connection; | ||
| 197 | |||
| 198 | # another brief code example of the Kafka package | ||
| 199 | # is provided in the "An Example" section. | ||
| 200 | |||
| 201 | =head1 ABSTRACT | ||
| 202 | |||
| 203 | The Kafka package is a set of Perl modules which provides a simple and | ||
| 204 | consistent application programming interface (API) to Apache Kafka 0.9+, | ||
| 205 | a high-throughput distributed messaging system. | ||
| 206 | |||
| 207 | =head1 DESCRIPTION | ||
| 208 | |||
| 209 | The user modules in this package provide an object oriented API. | ||
| 210 | The IO agents, requests sent, and responses received from the Apache Kafka | ||
| 211 | or mock servers are all represented by objects. | ||
| 212 | This makes a simple and powerful interface to these services. | ||
| 213 | |||
| 214 | The main features of the package are: | ||
| 215 | |||
| 216 | =over 3 | ||
| 217 | |||
| 218 | =item * | ||
| 219 | |||
| 220 | Contains various reusable components (modules) that can be used separately | ||
| 221 | or together. | ||
| 222 | |||
| 223 | =item * | ||
| 224 | |||
| 225 | Provides an object oriented model of communication. | ||
| 226 | |||
| 227 | =item * | ||
| 228 | |||
| 229 | Supports parsing the Apache Kafka protocol. | ||
| 230 | |||
| 231 | =item * | ||
| 232 | |||
| 233 | Supports the Apache Kafka Requests and Responses. Within this package the | ||
| 234 | following implements of Kafka's protocol are implemented: PRODUCE, FETCH, | ||
| 235 | OFFSETS, and METADATA. | ||
| 236 | |||
| 237 | =item * | ||
| 238 | |||
| 239 | Simple producer and consumer clients. | ||
| 240 | |||
| 241 | =item * | ||
| 242 | |||
| 243 | A simple interface to control the test Kafka server cluster | ||
| 244 | (in the test directory). | ||
| 245 | |||
| 246 | =item * | ||
| 247 | |||
| 248 | Simple mock server instance (located in the test directory) for testing without | ||
| 249 | Apache Kafka server. | ||
| 250 | |||
| 251 | =item * | ||
| 252 | |||
| 253 | Support for working with 64 bit elements of the Kafka protocol on 32 bit systems. | ||
| 254 | |||
| 255 | =item * | ||
| 256 | |||
| 257 | Taint mode support. | ||
| 258 | The input data is not checked for tainted. | ||
| 259 | Returns untainted data. | ||
| 260 | |||
| 261 | =back | ||
| 262 | |||
| 263 | =head1 APACHE KAFKA'S STYLE COMMUNICATION | ||
| 264 | |||
| 265 | The Kafka package is based on Kafka's 0.9+ Protocol specification document at | ||
| 266 | L<https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol> | ||
| 267 | |||
| 268 | =over 3 | ||
| 269 | |||
| 270 | =item | ||
| 271 | |||
| 272 | The Kafka's protocol is based on a request/response paradigm. | ||
| 273 | A client establishes a connection with a server and sends a request to the | ||
| 274 | server in the form of a request method, followed by a messages containing | ||
| 275 | request modifiers. The server responds with a success or error code, | ||
| 276 | followed by a messages containing entity meta-information and content. | ||
| 277 | |||
| 278 | Messages are the fundamental unit of communication. They are published to | ||
| 279 | a topic by a producer, which means they are physically sent to a server acting | ||
| 280 | as a broker. Some number of consumers subscribe to a topic, and each published | ||
| 281 | message is delivered to all the consumers. | ||
| 282 | The messages stream is partitioned on the brokers as a set of distinct | ||
| 283 | partitions. The semantic meaning of these partitions is left up to the producer | ||
| 284 | and the producer specifies which partition a message belongs to. Within | ||
| 285 | a partition the messages are stored in the order in which they arrive at the | ||
| 286 | broker, and will be given out to consumers in that same order. | ||
| 287 | In Apache Kafka, the consumers are responsible for maintaining state information | ||
| 288 | (offset) on what has been consumed. | ||
| 289 | A consumer can deliberately rewind back to an old offset and re-consume data. | ||
| 290 | Each message is uniquely identified by a 64-bit integer offset giving the | ||
| 291 | position of the start of this message in the stream of all messages ever sent | ||
| 292 | to that topic on that partition. | ||
| 293 | Reads are done by giving the 64-bit logical offset of a message and a max | ||
| 294 | chunk size. | ||
| 295 | |||
| 296 | The request is then passed through the client to a server and we get the | ||
| 297 | response in return to a consumer request that we can examine. | ||
| 298 | A request is always independent of any previous requests, i.e. the service | ||
| 299 | is stateless. | ||
| 300 | This API is completely stateless, with the topic and partition being passed in | ||
| 301 | on every request. | ||
| 302 | |||
| 303 | =back | ||
| 304 | |||
| 305 | =head2 The Connection Object | ||
| 306 | |||
| 307 | Clients use the Connection object to communicate with the Apache Kafka cluster. | ||
| 308 | The Connection object is an interface layer between your application code and | ||
| 309 | the Apache Kafka cluster. | ||
| 310 | |||
| 311 | Connection object is required to create instances of classes | ||
| 312 | L<Kafka::Producer|Kafka::Producer> or L<Kafka::Consumer|Kafka::Consumer>. | ||
| 313 | |||
| 314 | Kafka Connection API is implemented by L<Kafka::Connection|Kafka::Connection> class. | ||
| 315 | |||
| 316 | use Kafka::Connection; | ||
| 317 | |||
| 318 | # connect to local cluster with the defaults | ||
| 319 | my $connection = Kafka::Connection->new( host => 'localhost' ); | ||
| 320 | |||
| 321 | The main attributes of the Connection object are: | ||
| 322 | |||
| 323 | =over 3 | ||
| 324 | |||
| 325 | =item * | ||
| 326 | |||
| 327 | B<host> and B<port> are the IO object attributes denoting any server from the Kafka | ||
| 328 | cluster a client wants to connect. | ||
| 329 | |||
| 330 | =item * | ||
| 331 | |||
| 332 | B<timeout> specifies how much time remote servers is given to respond before | ||
| 333 | disconnection occurs and internal exception is thrown. | ||
| 334 | |||
| 335 | =back | ||
| 336 | |||
| 337 | =head2 The IO Object | ||
| 338 | |||
| 339 | The L<Kafka::Connection|Kafka::Connection> object use internal class L<Kafka::IO|Kafka::IO> | ||
| 340 | to maintain communication with the particular server of Kafka cluster | ||
| 341 | The IO object is an interface layer between L<Kafka::Connection|Kafka::Connection> object and | ||
| 342 | the network. | ||
| 343 | |||
| 344 | Kafka IO API is implemented by L<Kafka::IO|Kafka::IO> class. Note that end user | ||
| 345 | normally should have no need to use L<Kafka::IO|Kafka::IO> but work with | ||
| 346 | L<Kafka::Connection|Kafka::Connection> instead. | ||
| 347 | |||
| 348 | use Kafka::IO; | ||
| 349 | |||
| 350 | # connect to local server with the defaults | ||
| 351 | my $io = Kafka::IO->new( host => 'localhost' ); | ||
| 352 | |||
| 353 | The main attributes of the IO object are: | ||
| 354 | |||
| 355 | =over 3 | ||
| 356 | |||
| 357 | =item * | ||
| 358 | |||
| 359 | B<host> and B<port> are the IO object attributes denoting the server and | ||
| 360 | the port of Apache Kafka server. | ||
| 361 | |||
| 362 | =item * | ||
| 363 | |||
| 364 | B<timeout> specifies how much time is given remote servers to respond before | ||
| 365 | the IO object disconnects and generates an internal exception. | ||
| 366 | |||
| 367 | =back | ||
| 368 | |||
| 369 | =head2 The Producer Object | ||
| 370 | |||
| 371 | Kafka producer API is implemented by L<Kafka::Producer|Kafka::Producer> class. | ||
| 372 | |||
| 373 | use Kafka::Producer; | ||
| 374 | |||
| 375 | #-- Producer | ||
| 376 | my $producer = Kafka::Producer->new( Connection => $connection ); | ||
| 377 | |||
| 378 | # Sending a single message | ||
| 379 | $producer->send( | ||
| 380 | 'mytopic', # topic | ||
| 381 | 0, # partition | ||
| 382 | 'Single message' # message | ||
| 383 | ); | ||
| 384 | |||
| 385 | # Sending a series of messages | ||
| 386 | $producer->send( | ||
| 387 | 'mytopic', # topic | ||
| 388 | 0, # partition | ||
| 389 | [ # messages | ||
| 390 | 'The first message', | ||
| 391 | 'The second message', | ||
| 392 | 'The third message', | ||
| 393 | ] | ||
| 394 | ); | ||
| 395 | |||
| 396 | The main methods and attributes of the producer request are: | ||
| 397 | |||
| 398 | =over 3 | ||
| 399 | |||
| 400 | =item * | ||
| 401 | |||
| 402 | The request method of the producer object is C<send()>. | ||
| 403 | |||
| 404 | =item * | ||
| 405 | |||
| 406 | B<topic> and B<partition> define respective parameters of the B<messages> we | ||
| 407 | want to send. | ||
| 408 | |||
| 409 | =item * | ||
| 410 | |||
| 411 | B<messages> is an arbitrary amount of data (a simple data string or reference to | ||
| 412 | an array of the data strings). | ||
| 413 | |||
| 414 | =back | ||
| 415 | |||
| 416 | =head2 The Consumer Object | ||
| 417 | |||
| 418 | Kafka consumer API is implemented by L<Kafka::Consumer|Kafka::Consumer> class. | ||
| 419 | |||
| 420 | use Kafka::Consumer; | ||
| 421 | |||
| 422 | $consumer = Kafka::Consumer->new( Connection => $connection ); | ||
| 423 | |||
| 424 | The request methods of the consumer object are C<offsets()> and C<fetch()>. | ||
| 425 | |||
| 426 | C<offsets> method returns a reference to the list of offsets of received messages. | ||
| 427 | |||
| 428 | C<fetch> method returns a reference to the list of received | ||
| 429 | L<Kafka::Message|Kafka::Message> objects. | ||
| 430 | |||
| 431 | use Kafka qw( | ||
| 432 | $DEFAULT_MAX_BYTES | ||
| 433 | $DEFAULT_MAX_NUMBER_OF_OFFSETS | ||
| 434 | $RECEIVE_EARLIEST_OFFSET | ||
| 435 | ); | ||
| 436 | |||
| 437 | # Get a list of valid offsets up to max_number before the given time | ||
| 438 | my $offsets = $consumer->offsets( | ||
| 439 | 'mytopic', # topic | ||
| 440 | 0, # partition | ||
| 441 | $RECEIVE_EARLIEST_OFFSET, # time | ||
| 442 | $DEFAULT_MAX_NUMBER_OF_OFFSETS # max_number | ||
| 443 | ); | ||
| 444 | say "Received offset: $_" foreach @$offsets; | ||
| 445 | |||
| 446 | # Consuming messages | ||
| 447 | my $messages = $consumer->fetch( | ||
| 448 | 'mytopic', # topic | ||
| 449 | 0, # partition | ||
| 450 | 0, # offset | ||
| 451 | $DEFAULT_MAX_BYTES # Maximum size of MESSAGE(s) to receive | ||
| 452 | ); | ||
| 453 | foreach my $message ( @$messages ) { | ||
| 454 | if ( $message->valid ) { | ||
| 455 | say 'payload : ', $message->payload; | ||
| 456 | say 'key : ', $message->key; | ||
| 457 | say 'offset : ', $message->offset; | ||
| 458 | say 'next_offset: ', $message->next_offset; | ||
| 459 | } else { | ||
| 460 | say 'error : ', $message->error; | ||
| 461 | } | ||
| 462 | } | ||
| 463 | |||
| 464 | See L<Kafka::Consumer|Kafka::Consumer> for additional information and documentation about | ||
| 465 | class methods and arguments. | ||
| 466 | |||
| 467 | =head2 The Message Object | ||
| 468 | |||
| 469 | Kafka message API is implemented by L<Kafka::Message|Kafka::Message> class. | ||
| 470 | |||
| 471 | if ( $message->valid ) { | ||
| 472 | say 'payload : ', $message->payload; | ||
| 473 | say 'key : ', $message->key; | ||
| 474 | say 'offset : ', $message->offset; | ||
| 475 | say 'next_offset: ', $message->next_offset; | ||
| 476 | } else { | ||
| 477 | say 'error : ', $message->error; | ||
| 478 | } | ||
| 479 | |||
| 480 | Methods available for L<Kafka::Message|Kafka::Message> object : | ||
| 481 | |||
| 482 | =over 3 | ||
| 483 | |||
| 484 | =item * | ||
| 485 | |||
| 486 | C<payload> A simple message received from the Apache Kafka server. | ||
| 487 | |||
| 488 | =item * | ||
| 489 | |||
| 490 | C<key> An optional message key that was used for partition assignment. | ||
| 491 | |||
| 492 | =item * | ||
| 493 | |||
| 494 | C<valid> A message entry is valid. | ||
| 495 | |||
| 496 | =item * | ||
| 497 | |||
| 498 | C<error> A description of the message inconsistence. | ||
| 499 | |||
| 500 | =item * | ||
| 501 | |||
| 502 | C<offset> The offset beginning of the message in the Apache Kafka server. | ||
| 503 | |||
| 504 | =item * | ||
| 505 | |||
| 506 | C<next_offset> The offset beginning of the next message in the Apache Kafka | ||
| 507 | server. | ||
| 508 | |||
| 509 | =back | ||
| 510 | |||
| 511 | =head2 The Exception Object | ||
| 512 | |||
| 513 | A designated class C<Kafka::Exception> is used to provide a more detailed and | ||
| 514 | structured information when error is detected. | ||
| 515 | |||
| 516 | The following attributes are declared within C<Kafka::Exception>: | ||
| 517 | L<code|Kafka::Exceptions/code>, L<message|Kafka::Exceptions/message>. | ||
| 518 | |||
| 519 | Additional subclasses of C<Kafka::Exception> designed to report errors in respective | ||
| 520 | Kafka classes: | ||
| 521 | C<Kafka::Exception::Connection>, | ||
| 522 | C<Kafka::Exception::Consumer>, | ||
| 523 | C<Kafka::Exception::IO>, | ||
| 524 | C<Kafka::Exception::Int64>, | ||
| 525 | C<Kafka::Exception::Producer>. | ||
| 526 | |||
| 527 | Authors suggest using of L<Try::Tiny|Try::Tiny>'s C<try> and C<catch> to handle exceptions while | ||
| 528 | working with Kafka module. | ||
| 529 | |||
| 530 | =cut | ||
| 531 | |||
| 532 | =head1 EXPORT | ||
| 533 | |||
| 534 | None by default. | ||
| 535 | |||
| 536 | =head2 Additional constants | ||
| 537 | |||
| 538 | Additional constants are available for import, which can be used to define some | ||
| 539 | type of parameters, and to identify various error cases. | ||
| 540 | |||
| 541 | =over | ||
| 542 | |||
| 543 | =item C<$KAFKA_SERVER_PORT> | ||
| 544 | |||
| 545 | default Apache Kafka server port - 9092. | ||
| 546 | |||
| 547 | =cut | ||
| 548 | const our $KAFKA_SERVER_PORT => 9092; | ||
| 549 | |||
| 550 | =item C<$REQUEST_TIMEOUT> | ||
| 551 | |||
| 552 | 1.5 sec - timeout in secs, for C<gethostbyname>, C<connect>, blocking C<receive> and | ||
| 553 | C<send> calls (could be any integer or floating-point type). | ||
| 554 | |||
| 555 | =cut | ||
| 556 | const our $REQUEST_TIMEOUT => 1.5; | ||
| 557 | |||
| 558 | # Important configuration properties | ||
| 559 | |||
| 560 | =item C<$DEFAULT_MAX_BYTES> | ||
| 561 | |||
| 562 | 1MB - maximum size of message(s) to receive. | ||
| 563 | |||
| 564 | =cut | ||
| 565 | const our $DEFAULT_MAX_BYTES => 1_000_000; | ||
| 566 | |||
| 567 | =item C<$SEND_MAX_ATTEMPTS> | ||
| 568 | |||
| 569 | 4 - The leader may be unavailable transiently, which can fail the sending of a message. | ||
| 570 | This property specifies the number of attempts to send of a message. | ||
| 571 | |||
| 572 | Do not use C<$Kafka::SEND_MAX_ATTEMPTS> in C<Kafka::Producer-<gt>send> request to prevent duplicates. | ||
| 573 | |||
| 574 | =cut | ||
| 575 | const our $SEND_MAX_ATTEMPTS => 4; | ||
| 576 | |||
| 577 | =item C<$RETRY_BACKOFF> | ||
| 578 | |||
| 579 | 200 - (ms) | ||
| 580 | |||
| 581 | According to Apache Kafka documentation: | ||
| 582 | |||
| 583 | Producer Configs - | ||
| 584 | Before each retry, the producer refreshes the metadata of relevant topics. | ||
| 585 | Since leader election takes a bit of time, this property specifies the amount of time | ||
| 586 | that the producer waits before refreshing the metadata. | ||
| 587 | |||
| 588 | Consumer Configs - | ||
| 589 | Backoff time to wait before trying to determine the leader of a partition that has just lost its leader. | ||
| 590 | |||
| 591 | =cut | ||
| 592 | const our $RETRY_BACKOFF => 200; | ||
| 593 | |||
| 594 | # Used to ask for all messages before a certain time (ms). There are two special values. | ||
| 595 | |||
| 596 | =item C<$RECEIVE_LATEST_OFFSET> | ||
| 597 | |||
| 598 | B<DEPRECATED>: please use C<$RECEIVE_LATEST_OFFSETS>, as when using this | ||
| 599 | constant to retrieve offsets, you can get more than one. It's kept for backward | ||
| 600 | compatibility. | ||
| 601 | |||
| 602 | -1 : special value that denotes latest available offset. | ||
| 603 | |||
| 604 | =cut | ||
| 605 | const our $RECEIVE_LATEST_OFFSET => -1; # deprecated, this may return multiple offsets, so the naming is wrong). | ||
| 606 | |||
| 607 | =item C<$RECEIVE_LATEST_OFFSETS> | ||
| 608 | |||
| 609 | -1 : special value that denotes latest available offsets. | ||
| 610 | |||
| 611 | =cut | ||
| 612 | const our $RECEIVE_LATEST_OFFSETS => -1; # to receive the latest offsets. | ||
| 613 | |||
| 614 | =item C<$RECEIVE_EARLIEST_OFFSET> | ||
| 615 | |||
| 616 | -2 : special value that denotes earliest available offset. | ||
| 617 | |||
| 618 | =cut | ||
| 619 | const our $RECEIVE_EARLIEST_OFFSET => -2; | ||
| 620 | |||
| 621 | =item C<$RECEIVE_EARLIEST_OFFSETS> | ||
| 622 | |||
| 623 | B<DEPRECATED>: please use C<$RECEIVE_EARLIEST_OFFSET>, as when using this | ||
| 624 | constant to retrieve offset, you can get only one. It's kept for backward | ||
| 625 | compatibility. | ||
| 626 | |||
| 627 | -2 : special value that denotes earliest available offset. | ||
| 628 | |||
| 629 | =cut | ||
| 630 | const our $RECEIVE_EARLIEST_OFFSETS => -2; | ||
| 631 | |||
| 632 | =item C<$DEFAULT_MAX_NUMBER_OF_OFFSETS> | ||
| 633 | |||
| 634 | 100 - maximum number of offsets to retrieve. | ||
| 635 | |||
| 636 | =cut | ||
| 637 | const our $DEFAULT_MAX_NUMBER_OF_OFFSETS => 100; | ||
| 638 | |||
| 639 | =item C<$MIN_BYTES_RESPOND_IMMEDIATELY> | ||
| 640 | |||
| 641 | The minimum number of bytes of messages that must be available to give a response. | ||
| 642 | |||
| 643 | 0 - the server will always respond immediately. | ||
| 644 | |||
| 645 | =cut | ||
| 646 | const our $MIN_BYTES_RESPOND_IMMEDIATELY => 0; | ||
| 647 | |||
| 648 | =item C<$MIN_BYTES_RESPOND_HAS_DATA> | ||
| 649 | |||
| 650 | The minimum number of bytes of messages that must be available to give a response. | ||
| 651 | |||
| 652 | 10 - the server will respond as soon as at least one partition has at least 10 bytes of data | ||
| 653 | (Offset => int64 + MessageSize => int32) | ||
| 654 | or the specified timeout occurs. | ||
| 655 | |||
| 656 | =cut | ||
| 657 | const our $MIN_BYTES_RESPOND_HAS_DATA => 10; | ||
| 658 | |||
| 659 | =item C<$NOT_SEND_ANY_RESPONSE> | ||
| 660 | |||
| 661 | Indicates how many acknowledgements the servers should receive before responding to the request. | ||
| 662 | |||
| 663 | 0 - the server does not send any response. | ||
| 664 | |||
| 665 | =cut | ||
| 666 | const our $NOT_SEND_ANY_RESPONSE => 0; | ||
| 667 | |||
| 668 | =item C<$WAIT_WRITTEN_TO_LOCAL_LOG> | ||
| 669 | |||
| 670 | Indicates how long the servers should wait for the data to be written to the local long before responding to the request. | ||
| 671 | |||
| 672 | 1 - the server will wait the data is written to the local log before sending a response. | ||
| 673 | |||
| 674 | =cut | ||
| 675 | const our $WAIT_WRITTEN_TO_LOCAL_LOG => 1; | ||
| 676 | |||
| 677 | =item C<$BLOCK_UNTIL_IS_COMMITTED> | ||
| 678 | |||
| 679 | Wait for message to be committed by all sync replicas. | ||
| 680 | |||
| 681 | -1 - the server will block until the message is committed by all in sync replicas before sending a response. | ||
| 682 | |||
| 683 | =cut | ||
| 684 | const our $BLOCK_UNTIL_IS_COMMITTED => -1; | ||
| 685 | |||
| 686 | =item C<$DEFAULT_MAX_WAIT_TIME> | ||
| 687 | |||
| 688 | The maximum amount of time (seconds, may be fractional) to wait when no sufficient amount of data is available | ||
| 689 | at the time the request is dispatched. | ||
| 690 | |||
| 691 | 0.1 - allow the server to wait up to 0.1s to try to accumulate data before responding. | ||
| 692 | |||
| 693 | =cut | ||
| 694 | const our $DEFAULT_MAX_WAIT_TIME => 0.1; | ||
| 695 | |||
| 696 | =item C<$MESSAGE_SIZE_OVERHEAD> | ||
| 697 | |||
| 698 | 34 - size of protocol overhead (data added by protocol) for each message. | ||
| 699 | |||
| 700 | =back | ||
| 701 | |||
| 702 | =cut | ||
| 703 | # Look at the structure of 'Message sets' | ||
| 704 | # https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-Messagesets | ||
| 705 | # for example the case with an empty key: | ||
| 706 | # Message format: | ||
| 707 | # v0 | ||
| 708 | # Message => Crc MagicByte Attributes Key Value | ||
| 709 | # Crc => int32 | ||
| 710 | # MagicByte => int8 | ||
| 711 | # Attributes => int8 | ||
| 712 | # Key => bytes | ||
| 713 | # Value => bytes | ||
| 714 | # | ||
| 715 | # MessageSet => [Offset MessageSize Message] | ||
| 716 | # 00:00:00:00:00:00:00:00: # Offset => int64 | ||
| 717 | # 00:00:00:14: # MessageSize => int32 (a size 0x14 = 20 bytes) | ||
| 718 | # Message => Crc MagicByte Attributes Key Value | ||
| 719 | # 8d:c7:95:a2: # Crc => int32 | ||
| 720 | # 00: # MagicByte => int8 | ||
| 721 | # 00: # Attributes => int8 (the lowest 2 bits - Compression None) | ||
| 722 | # ff:ff:ff:ff: # Key => bytes (a length -1 = null bytes) | ||
| 723 | # 00:00:00:06: # Value => bytes (a length 0x6 = 6 bytes) | ||
| 724 | # | ||
| 725 | # v1 (supported since 0.10.0) | ||
| 726 | # Message => Crc MagicByte Attributes Key Value | ||
| 727 | # Crc => int32 | ||
| 728 | # MagicByte => int8 | ||
| 729 | # Attributes => int8 | ||
| 730 | # Timestamp => int64 # new since 0.10.0 | ||
| 731 | # Key => bytes | ||
| 732 | # Value => bytes | ||
| 733 | const our $MESSAGE_SIZE_OVERHEAD => 34; | ||
| 734 | |||
| 735 | =pod | ||
| 736 | |||
| 737 | =head2 IP version | ||
| 738 | |||
| 739 | Specify IP protocol version for resolving of IP address and host names. | ||
| 740 | |||
| 741 | =over | ||
| 742 | |||
| 743 | =item C<$IP_V4> | ||
| 744 | |||
| 745 | Interpret address as IPv4 and force resolving of host name in IPv4. | ||
| 746 | |||
| 747 | =cut | ||
| 748 | const our $IP_V4 => 4; | ||
| 749 | |||
| 750 | =item C<$IP_V6> | ||
| 751 | |||
| 752 | Interpret address as IPv6 and force resolving of host name in IPv6. | ||
| 753 | |||
| 754 | =back | ||
| 755 | |||
| 756 | =cut | ||
| 757 | const our $IP_V6 => 6; | ||
| 758 | |||
| 759 | #-- Codec numbers: | ||
| 760 | |||
| 761 | =pod | ||
| 762 | |||
| 763 | =head2 Compression | ||
| 764 | |||
| 765 | According to Apache Kafka documentation: | ||
| 766 | |||
| 767 | Kafka currently supports three compression codecs with the following codec numbers: | ||
| 768 | |||
| 769 | =over | ||
| 770 | |||
| 771 | =item C<$COMPRESSION_NONE> | ||
| 772 | |||
| 773 | None = 0 | ||
| 774 | |||
| 775 | =cut | ||
| 776 | const our $COMPRESSION_NONE => 0; | ||
| 777 | |||
| 778 | =item C<$COMPRESSION_GZIP> | ||
| 779 | |||
| 780 | GZIP = 1 | ||
| 781 | |||
| 782 | =cut | ||
| 783 | const our $COMPRESSION_GZIP => 1; | ||
| 784 | |||
| 785 | =item C<$COMPRESSION_SNAPPY> | ||
| 786 | |||
| 787 | Snappy = 2 | ||
| 788 | |||
| 789 | =cut | ||
| 790 | const our $COMPRESSION_SNAPPY => 2; | ||
| 791 | |||
| 792 | =item C<$COMPRESSION_LZ4> | ||
| 793 | |||
| 794 | LZ4 = 3 | ||
| 795 | (That module supports only Kafka 0.10 or higher, as initial implementation of LZ4 in Kafka did not follow the standard LZ4 framing specification). | ||
| 796 | |||
| 797 | =cut | ||
| 798 | const our $COMPRESSION_LZ4 => 3; | ||
| 799 | |||
| 800 | =back | ||
| 801 | |||
| 802 | =head2 Error codes | ||
| 803 | |||
| 804 | Possible error codes (corresponds to descriptions in C<%ERROR>): | ||
| 805 | |||
| 806 | =over | ||
| 807 | |||
| 808 | =item C<$ERROR_MISMATCH_ARGUMENT> | ||
| 809 | |||
| 810 | -1000 - Invalid argument | ||
| 811 | |||
| 812 | =cut | ||
| 813 | const our $ERROR_MISMATCH_ARGUMENT => -1000; | ||
| 814 | |||
| 815 | =item C<$ERROR_CANNOT_SEND> | ||
| 816 | |||
| 817 | -1001 - Cannot send | ||
| 818 | |||
| 819 | =cut | ||
| 820 | const our $ERROR_CANNOT_SEND => -1001; | ||
| 821 | |||
| 822 | =item C<$ERROR_SEND_NO_ACK> | ||
| 823 | |||
| 824 | -1002 - No acknowledgement for sent request | ||
| 825 | |||
| 826 | =cut | ||
| 827 | const our $ERROR_SEND_NO_ACK => -1002; | ||
| 828 | |||
| 829 | =item C<ERROR_CANNOT_RECV> | ||
| 830 | |||
| 831 | -1003 - Cannot receive | ||
| 832 | |||
| 833 | =cut | ||
| 834 | const our $ERROR_CANNOT_RECV => -1003; | ||
| 835 | |||
| 836 | =item C<ERROR_CANNOT_BIND> | ||
| 837 | |||
| 838 | -1004 - Cannot connect to broker | ||
| 839 | |||
| 840 | =cut | ||
| 841 | const our $ERROR_CANNOT_BIND => -1004; | ||
| 842 | |||
| 843 | =item C<$ERROR_METADATA_ATTRIBUTES> | ||
| 844 | |||
| 845 | -1005 - Unknown metadata attributes | ||
| 846 | |||
| 847 | =cut | ||
| 848 | const our $ERROR_METADATA_ATTRIBUTES => -1005; | ||
| 849 | |||
| 850 | =item C<$ERROR_UNKNOWN_APIKEY> | ||
| 851 | |||
| 852 | -1006 - Unknown ApiKey | ||
| 853 | |||
| 854 | =cut | ||
| 855 | const our $ERROR_UNKNOWN_APIKEY => -1006; | ||
| 856 | |||
| 857 | =item C<$ERROR_CANNOT_GET_METADATA> | ||
| 858 | |||
| 859 | -1007 - Cannot get Metadata | ||
| 860 | |||
| 861 | =cut | ||
| 862 | const our $ERROR_CANNOT_GET_METADATA => -1007; | ||
| 863 | |||
| 864 | =item C<$ERROR_LEADER_NOT_FOUND> | ||
| 865 | |||
| 866 | -1008 - Leader not found | ||
| 867 | |||
| 868 | =cut | ||
| 869 | const our $ERROR_LEADER_NOT_FOUND => -1008; | ||
| 870 | |||
| 871 | =item C<$ERROR_MISMATCH_CORRELATIONID> | ||
| 872 | |||
| 873 | -1009 - Mismatch CorrelationId | ||
| 874 | |||
| 875 | =cut | ||
| 876 | const our $ERROR_MISMATCH_CORRELATIONID => -1009; | ||
| 877 | |||
| 878 | =item C<$ERROR_NO_KNOWN_BROKERS> | ||
| 879 | |||
| 880 | -1010 - There are no known brokers | ||
| 881 | |||
| 882 | =cut | ||
| 883 | const our $ERROR_NO_KNOWN_BROKERS => -1010; | ||
| 884 | |||
| 885 | =item C<$ERROR_REQUEST_OR_RESPONSE> | ||
| 886 | |||
| 887 | -1011 - Bad request or response element | ||
| 888 | |||
| 889 | =cut | ||
| 890 | const our $ERROR_REQUEST_OR_RESPONSE => -1011; | ||
| 891 | |||
| 892 | =item C<$ERROR_TOPIC_DOES_NOT_MATCH> | ||
| 893 | |||
| 894 | -1012 - Topic does not match the requested | ||
| 895 | |||
| 896 | =cut | ||
| 897 | const our $ERROR_TOPIC_DOES_NOT_MATCH => -1012; | ||
| 898 | |||
| 899 | =item C<$ERROR_PARTITION_DOES_NOT_MATCH> | ||
| 900 | |||
| 901 | -1013 - Partition does not match the requested | ||
| 902 | |||
| 903 | =cut | ||
| 904 | const our $ERROR_PARTITION_DOES_NOT_MATCH => -1013; | ||
| 905 | |||
| 906 | =item C<$ERROR_NOT_BINARY_STRING> | ||
| 907 | |||
| 908 | -1014 - Not binary string | ||
| 909 | |||
| 910 | =cut | ||
| 911 | const our $ERROR_NOT_BINARY_STRING => -1014; | ||
| 912 | |||
| 913 | =item C<$ERROR_COMPRESSION> | ||
| 914 | |||
| 915 | -1015 - Compression error | ||
| 916 | |||
| 917 | =cut | ||
| 918 | const our $ERROR_COMPRESSION => -1015; | ||
| 919 | |||
| 920 | =item C<$ERROR_RESPONSEMESSAGE_NOT_RECEIVED> | ||
| 921 | |||
| 922 | -1016 - 'ResponseMessage' not received | ||
| 923 | |||
| 924 | =cut | ||
| 925 | const our $ERROR_RESPONSEMESSAGE_NOT_RECEIVED => -1016; | ||
| 926 | |||
| 927 | =item C<$ERROR_INCOMPATIBLE_HOST_IP_VERSION> | ||
| 928 | |||
| 929 | -1017 - Incompatible host name and IP version | ||
| 930 | |||
| 931 | =cut | ||
| 932 | const our $ERROR_INCOMPATIBLE_HOST_IP_VERSION => -1017; | ||
| 933 | |||
| 934 | |||
| 935 | =item C<$ERROR_NO_CONNECTION> | ||
| 936 | |||
| 937 | -1018 - No IO connection | ||
| 938 | |||
| 939 | =cut | ||
| 940 | const our $ERROR_NO_CONNECTION => -1018; | ||
| 941 | |||
| 942 | =item C<$ERROR_GROUP_COORDINATOR_NOT_FOUND> | ||
| 943 | |||
| 944 | -1019 - Group Coordinator not found | ||
| 945 | |||
| 946 | =cut | ||
| 947 | const our $ERROR_GROUP_COORDINATOR_NOT_FOUND => -1019; | ||
| 948 | |||
| 949 | =back | ||
| 950 | |||
| 951 | Contains the descriptions of possible error codes obtained via ERROR_CODE box | ||
| 952 | of Apache Kafka Wire Format protocol response. | ||
| 953 | |||
| 954 | =over | ||
| 955 | |||
| 956 | =cut | ||
| 957 | |||
| 958 | #-- The Protocol Error Codes | ||
| 959 | |||
| 960 | # According | ||
| 961 | # https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-ErrorCodes | ||
| 962 | |||
| 963 | =item C<$ERROR_NO_ERROR> | ||
| 964 | |||
| 965 | 0 - C<q{}> | ||
| 966 | |||
| 967 | No error - it worked! | ||
| 968 | |||
| 969 | =cut | ||
| 970 | const our $ERROR_NO_ERROR => 0; | ||
| 971 | |||
| 972 | =item C<$ERROR_UNKNOWN> | ||
| 973 | |||
| 974 | -1 - An unexpected server error. | ||
| 975 | |||
| 976 | =cut | ||
| 977 | const our $ERROR_UNKNOWN => -1; | ||
| 978 | |||
| 979 | =item C<$ERROR_OFFSET_OUT_OF_RANGE> | ||
| 980 | |||
| 981 | 1 - The requested offset is not within the range of offsets maintained by the server. | ||
| 982 | |||
| 983 | =cut | ||
| 984 | const our $ERROR_OFFSET_OUT_OF_RANGE => 1; | ||
| 985 | |||
| 986 | =item C<$ERROR_INVALID_MESSAGE> | ||
| 987 | |||
| 988 | 2 - This message has failed its CRC checksum, exceeds the valid size, or is otherwise corrupt. | ||
| 989 | |||
| 990 | Synonym name $ERROR_CORRUPT_MESSAGE . | ||
| 991 | |||
| 992 | =cut | ||
| 993 | const our $ERROR_INVALID_MESSAGE => 2; | ||
| 994 | const our $ERROR_CORRUPT_MESSAGE => 2; | ||
| 995 | |||
| 996 | =item C<$ERROR_UNKNOWN_TOPIC_OR_PARTITION> | ||
| 997 | |||
| 998 | 3 - This server does not host this topic-partition. | ||
| 999 | |||
| 1000 | =cut | ||
| 1001 | const our $ERROR_UNKNOWN_TOPIC_OR_PARTITION => 3; | ||
| 1002 | |||
| 1003 | =item C<$ERROR_INVALID_FETCH_SIZE> | ||
| 1004 | |||
| 1005 | 4 - The requested fetch size is invalid. | ||
| 1006 | |||
| 1007 | Synonym name $ERROR_INVALID_MESSAGE_SIZE . | ||
| 1008 | |||
| 1009 | =cut | ||
| 1010 | const our $ERROR_INVALID_MESSAGE_SIZE => 4; | ||
| 1011 | const our $ERROR_INVALID_FETCH_SIZE => 4; | ||
| 1012 | |||
| 1013 | =item C<$ERROR_LEADER_NOT_AVAILABLE> | ||
| 1014 | |||
| 1015 | 5 - Unable to write due to ongoing Kafka leader selection. | ||
| 1016 | |||
| 1017 | This error is thrown if we are in the middle of a leadership election and there is | ||
| 1018 | no current leader for this partition, hence it is unavailable for writes. | ||
| 1019 | |||
| 1020 | =cut | ||
| 1021 | const our $ERROR_LEADER_NOT_AVAILABLE => 5; | ||
| 1022 | |||
| 1023 | =item C<$ERROR_NOT_LEADER_FOR_PARTITION> | ||
| 1024 | |||
| 1025 | 6 - Server is not a leader for partition. | ||
| 1026 | |||
| 1027 | This error is thrown if the client attempts to send messages to a replica that is not the leader for some partition. | ||
| 1028 | It indicates that the clients metadata is out of date. | ||
| 1029 | |||
| 1030 | =cut | ||
| 1031 | const our $ERROR_NOT_LEADER_FOR_PARTITION => 6; | ||
| 1032 | |||
| 1033 | =item C<$ERROR_REQUEST_TIMED_OUT> | ||
| 1034 | |||
| 1035 | 7 - Request time-out. | ||
| 1036 | |||
| 1037 | This error is thrown if the request exceeds the user-specified time limit in the request. | ||
| 1038 | |||
| 1039 | =cut | ||
| 1040 | const our $ERROR_REQUEST_TIMED_OUT => 7; | ||
| 1041 | |||
| 1042 | =item C<$ERROR_BROKER_NOT_AVAILABLE> | ||
| 1043 | |||
| 1044 | 8 - Broker is not available. | ||
| 1045 | |||
| 1046 | This is not a client facing error and is used mostly by tools when a broker is not alive. | ||
| 1047 | |||
| 1048 | =cut | ||
| 1049 | const our $ERROR_BROKER_NOT_AVAILABLE => 8; | ||
| 1050 | |||
| 1051 | =item C<$ERROR_REPLICA_NOT_AVAILABLE> | ||
| 1052 | |||
| 1053 | 9 - The replica is not available for the requested topic-partition. | ||
| 1054 | |||
| 1055 | If replica is expected on a broker, but is not (this can be safely ignored). | ||
| 1056 | |||
| 1057 | =cut | ||
| 1058 | const our $ERROR_REPLICA_NOT_AVAILABLE => 9; | ||
| 1059 | |||
| 1060 | =item C<$ERROR_MESSAGE_TOO_LARGE> | ||
| 1061 | |||
| 1062 | 10 - The request included a message larger than the max message size the server will accept. | ||
| 1063 | |||
| 1064 | The server has a configurable maximum message size to avoid unbounded memory allocation. | ||
| 1065 | This error is thrown if the client attempt to produce a message larger than this maximum. | ||
| 1066 | |||
| 1067 | Synonym name $ERROR_MESSAGE_SIZE_TOO_LARGE . | ||
| 1068 | |||
| 1069 | =cut | ||
| 1070 | const our $ERROR_MESSAGE_SIZE_TOO_LARGE => 10; | ||
| 1071 | const our $ERROR_MESSAGE_TOO_LARGE => 10; | ||
| 1072 | |||
| 1073 | =item C<$ERROR_STALE_CONTROLLER_EPOCH> | ||
| 1074 | |||
| 1075 | 11 - The controller moved to another broker. | ||
| 1076 | |||
| 1077 | According to Apache Kafka documentation: | ||
| 1078 | Internal error code for broker-to-broker communication. | ||
| 1079 | |||
| 1080 | Synonym name $ERROR_STALE_CONTROLLER_EPOCH_CODE . | ||
| 1081 | |||
| 1082 | =cut | ||
| 1083 | const our $ERROR_STALE_CONTROLLER_EPOCH_CODE => 11; | ||
| 1084 | const our $ERROR_STALE_CONTROLLER_EPOCH => 11; | ||
| 1085 | |||
| 1086 | =item C<$ERROR_OFFSET_METADATA_TOO_LARGE> | ||
| 1087 | |||
| 1088 | 12 - Specified metadata offset is too big | ||
| 1089 | |||
| 1090 | If you specify a value larger than configured maximum for offset metadata. | ||
| 1091 | |||
| 1092 | Synonym name $ERROR_OFFSET_METADATA_TOO_LARGE_CODE . | ||
| 1093 | |||
| 1094 | =cut | ||
| 1095 | const our $ERROR_OFFSET_METADATA_TOO_LARGE => 12; | ||
| 1096 | const our $ERROR_OFFSET_METADATA_TOO_LARGE_CODE => 12; | ||
| 1097 | |||
| 1098 | =item C<$ERROR_NETWORK_EXCEPTION> | ||
| 1099 | |||
| 1100 | 13 - The server disconnected before a response was received. | ||
| 1101 | |||
| 1102 | =cut | ||
| 1103 | const our $ERROR_NETWORK_EXCEPTION => 13; | ||
| 1104 | |||
| 1105 | =item C<$ERROR_GROUP_LOAD_IN_PROGRESS> | ||
| 1106 | |||
| 1107 | 14 - The coordinator is loading and hence can't process requests for this group. | ||
| 1108 | |||
| 1109 | Synonym name $ERROR_GROUP_LOAD_IN_PROGRESS_CODE, $ERROR_LOAD_IN_PROGRESS_CODE . | ||
| 1110 | |||
| 1111 | =cut | ||
| 1112 | const our $ERROR_LOAD_IN_PROGRESS_CODE => 14; | ||
| 1113 | const our $ERROR_GROUP_LOAD_IN_PROGRESS => 14; | ||
| 1114 | const our $ERROR_GROUP_LOAD_IN_PROGRESS_CODE => 14; | ||
| 1115 | |||
| 1116 | =item C<$ERROR_GROUP_COORDINATOR_NOT_AVAILABLE> | ||
| 1117 | |||
| 1118 | 15 - The group coordinator is not available. | ||
| 1119 | |||
| 1120 | Synonym name $ERROR_GROUP_COORDINATOR_NOT_AVAILABLE_CODE, $ERROR_CONSUMER_COORDINATOR_NOT_AVAILABLE_CODE . | ||
| 1121 | |||
| 1122 | =cut | ||
| 1123 | const our $ERROR_CONSUMER_COORDINATOR_NOT_AVAILABLE_CODE => 15; | ||
| 1124 | const our $ERROR_GROUP_COORDINATOR_NOT_AVAILABLE => 15; | ||
| 1125 | const our $ERROR_GROUP_COORDINATOR_NOT_AVAILABLE_CODE => 15; | ||
| 1126 | |||
| 1127 | =item C<$ERROR_NOT_COORDINATOR_FOR_GROUP> | ||
| 1128 | |||
| 1129 | 16 - This is not the correct coordinator for this group. | ||
| 1130 | |||
| 1131 | Synonym name $ERROR_NOT_COORDINATOR_FOR_GROUP_CODE, $ERROR_NOT_COORDINATOR_FOR_CONSUMER_CODE . | ||
| 1132 | |||
| 1133 | =cut | ||
| 1134 | const our $ERROR_NOT_COORDINATOR_FOR_CONSUMER_CODE => 16; | ||
| 1135 | const our $ERROR_NOT_COORDINATOR_FOR_GROUP => 16; | ||
| 1136 | const our $ERROR_NOT_COORDINATOR_FOR_GROUP_CODE => 16; | ||
| 1137 | |||
| 1138 | =item C<$ERROR_INVALID_TOPIC_EXCEPTION> | ||
| 1139 | |||
| 1140 | 17 - The request attempted to perform an operation on an invalid topic. | ||
| 1141 | |||
| 1142 | Synonym name $ERROR_INVALID_TOPIC_CODE . | ||
| 1143 | |||
| 1144 | =cut | ||
| 1145 | const our $ERROR_INVALID_TOPIC_CODE => 17; | ||
| 1146 | const our $ERROR_INVALID_TOPIC_EXCEPTION => 17; | ||
| 1147 | |||
| 1148 | =item C<$ERROR_RECORD_LIST_TOO_LARGE> | ||
| 1149 | |||
| 1150 | 18 - The request included message batch larger than the configured segment size on the server. | ||
| 1151 | |||
| 1152 | Synonym name $ERROR_RECORD_LIST_TOO_LARGE_CODE . | ||
| 1153 | |||
| 1154 | =cut | ||
| 1155 | const our $ERROR_RECORD_LIST_TOO_LARGE => 18; | ||
| 1156 | const our $ERROR_RECORD_LIST_TOO_LARGE_CODE => 18; | ||
| 1157 | |||
| 1158 | =item C<$ERROR_NOT_ENOUGH_REPLICAS> | ||
| 1159 | |||
| 1160 | 19 - Messages are rejected since there are fewer in-sync replicas than required. | ||
| 1161 | |||
| 1162 | Synonym name $ERROR_NOT_ENOUGH_REPLICAS_CODE . | ||
| 1163 | |||
| 1164 | =cut | ||
| 1165 | const our $ERROR_NOT_ENOUGH_REPLICAS => 19; | ||
| 1166 | const our $ERROR_NOT_ENOUGH_REPLICAS_CODE => 19; | ||
| 1167 | |||
| 1168 | =item C<$ERROR_NOT_ENOUGH_REPLICAS_AFTER_APPEND> | ||
| 1169 | |||
| 1170 | 20 - Messages are written to the log, but to fewer in-sync replicas than required. | ||
| 1171 | |||
| 1172 | Synonym name $ERROR_NOT_ENOUGH_REPLICAS_AFTER_APPEND_CODE . | ||
| 1173 | |||
| 1174 | =cut | ||
| 1175 | const our $ERROR_NOT_ENOUGH_REPLICAS_AFTER_APPEND => 20; | ||
| 1176 | const our $ERROR_NOT_ENOUGH_REPLICAS_AFTER_APPEND_CODE => 20; | ||
| 1177 | |||
| 1178 | =item C<$ERROR_INVALID_REQUIRED_ACKS> | ||
| 1179 | |||
| 1180 | 21 - Produce request specified an invalid value for required acks. | ||
| 1181 | |||
| 1182 | Synonym name $ERROR_INVALID_REQUIRED_ACKS_CODE . | ||
| 1183 | |||
| 1184 | =cut | ||
| 1185 | const our $ERROR_INVALID_REQUIRED_ACKS => 21; | ||
| 1186 | const our $ERROR_INVALID_REQUIRED_ACKS_CODE => 21; | ||
| 1187 | |||
| 1188 | =item C<$ERROR_ILLEGAL_GENERATION> | ||
| 1189 | |||
| 1190 | 22 - Specified group generation id is not valid. | ||
| 1191 | |||
| 1192 | Synonym name $ERROR_ILLEGAL_GENERATION_CODE . | ||
| 1193 | |||
| 1194 | =cut | ||
| 1195 | const our $ERROR_ILLEGAL_GENERATION => 22; | ||
| 1196 | const our $ERROR_ILLEGAL_GENERATION_CODE => 22; | ||
| 1197 | |||
| 1198 | =item C<$ERROR_INCONSISTENT_GROUP_PROTOCOL> | ||
| 1199 | |||
| 1200 | 23 - The group member's supported protocols are incompatible with those of existing members. | ||
| 1201 | |||
| 1202 | Synonym name $ERROR_INCONSISTENT_GROUP_PROTOCOL_CODE . | ||
| 1203 | |||
| 1204 | =cut | ||
| 1205 | const our $ERROR_INCONSISTENT_GROUP_PROTOCOL => 23; | ||
| 1206 | const our $ERROR_INCONSISTENT_GROUP_PROTOCOL_CODE => 23; | ||
| 1207 | |||
| 1208 | =item C<$ERROR_INVALID_GROUP_ID> | ||
| 1209 | |||
| 1210 | 24 - The configured groupId is invalid. | ||
| 1211 | |||
| 1212 | Synonym name $ERROR_INVALID_GROUP_ID_CODE . | ||
| 1213 | |||
| 1214 | =cut | ||
| 1215 | const our $ERROR_INVALID_GROUP_ID => 24; | ||
| 1216 | const our $ERROR_INVALID_GROUP_ID_CODE => 24; | ||
| 1217 | |||
| 1218 | =item C<$ERROR_UNKNOWN_MEMBER_ID> | ||
| 1219 | |||
| 1220 | 25 - The coordinator is not aware of this member. | ||
| 1221 | |||
| 1222 | Synonym name $ERROR_UNKNOWN_MEMBER_ID_CODE . | ||
| 1223 | |||
| 1224 | =cut | ||
| 1225 | const our $ERROR_UNKNOWN_MEMBER_ID => 25; | ||
| 1226 | const our $ERROR_UNKNOWN_MEMBER_ID_CODE => 25; | ||
| 1227 | |||
| 1228 | =item C<$ERROR_INVALID_SESSION_TIMEOUT> | ||
| 1229 | |||
| 1230 | 26 - The session timeout is not within the range allowed by the broker | ||
| 1231 | (as configured by group.min.session.timeout.ms and group.max.session.timeout.ms). | ||
| 1232 | |||
| 1233 | Synonym name $ERROR_INVALID_SESSION_TIMEOUT_CODE . | ||
| 1234 | |||
| 1235 | =cut | ||
| 1236 | const our $ERROR_INVALID_SESSION_TIMEOUT => 26; | ||
| 1237 | const our $ERROR_INVALID_SESSION_TIMEOUT_CODE => 26; | ||
| 1238 | |||
| 1239 | =item C<$ERROR_REBALANCE_IN_PROGRESS> | ||
| 1240 | |||
| 1241 | 27 - The group is rebalancing, so a rejoin is needed. | ||
| 1242 | |||
| 1243 | Synonym name $ERROR_REBALANCE_IN_PROGRESS_CODE . | ||
| 1244 | |||
| 1245 | =cut | ||
| 1246 | const our $ERROR_REBALANCE_IN_PROGRESS => 27; | ||
| 1247 | const our $ERROR_REBALANCE_IN_PROGRESS_CODE => 27; | ||
| 1248 | |||
| 1249 | =item C<$ERROR_INVALID_COMMIT_OFFSET_SIZE> | ||
| 1250 | |||
| 1251 | 28 - The committing offset data size is not valid. | ||
| 1252 | |||
| 1253 | Synonym name $ERROR_INVALID_COMMIT_OFFSET_SIZE_CODE . | ||
| 1254 | |||
| 1255 | =cut | ||
| 1256 | const our $ERROR_INVALID_COMMIT_OFFSET_SIZE => 28; | ||
| 1257 | const our $ERROR_INVALID_COMMIT_OFFSET_SIZE_CODE => 28; | ||
| 1258 | |||
| 1259 | =item C<$ERROR_TOPIC_AUTHORIZATION_FAILED> | ||
| 1260 | |||
| 1261 | 29 - Not authorized to access topics: [Topic authorization failed.]. | ||
| 1262 | |||
| 1263 | Synonym name $ERROR_TOPIC_AUTHORIZATION_FAILED_CODE . | ||
| 1264 | |||
| 1265 | =cut | ||
| 1266 | const our $ERROR_TOPIC_AUTHORIZATION_FAILED => 29; | ||
| 1267 | const our $ERROR_TOPIC_AUTHORIZATION_FAILED_CODE => 29; | ||
| 1268 | |||
| 1269 | =item C<$ERROR_GROUP_AUTHORIZATION_FAILED> | ||
| 1270 | |||
| 1271 | 30 - Not authorized to access group: Group authorization failed. | ||
| 1272 | |||
| 1273 | Synonym name $ERROR_GROUP_AUTHORIZATION_FAILED_CODE . | ||
| 1274 | |||
| 1275 | =cut | ||
| 1276 | const our $ERROR_GROUP_AUTHORIZATION_FAILED => 30; | ||
| 1277 | const our $ERROR_GROUP_AUTHORIZATION_FAILED_CODE => 30; | ||
| 1278 | |||
| 1279 | =item C<$ERROR_CLUSTER_AUTHORIZATION_FAILED> | ||
| 1280 | |||
| 1281 | 31 - Cluster authorization failed. | ||
| 1282 | |||
| 1283 | Synonym name $ERROR_CLUSTER_AUTHORIZATION_FAILED_CODE . | ||
| 1284 | |||
| 1285 | =cut | ||
| 1286 | const our $ERROR_CLUSTER_AUTHORIZATION_FAILED => 31; | ||
| 1287 | const our $ERROR_CLUSTER_AUTHORIZATION_FAILED_CODE => 31; | ||
| 1288 | |||
| 1289 | =item C<$ERROR_INVALID_TIMESTAMP> | ||
| 1290 | |||
| 1291 | 32 - The timestamp of the message is out of acceptable range. | ||
| 1292 | |||
| 1293 | =cut | ||
| 1294 | const our $ERROR_INVALID_TIMESTAMP => 32; | ||
| 1295 | |||
| 1296 | =item C<$ERROR_UNSUPPORTED_SASL_MECHANISM> | ||
| 1297 | |||
| 1298 | 33 - The broker does not support the requested SASL mechanism. | ||
| 1299 | |||
| 1300 | =cut | ||
| 1301 | const our $ERROR_UNSUPPORTED_SASL_MECHANISM => 33; | ||
| 1302 | |||
| 1303 | =item C<$ERROR_ILLEGAL_SASL_STATE> | ||
| 1304 | |||
| 1305 | 34 - Request is not valid given the current SASL state. | ||
| 1306 | |||
| 1307 | =cut | ||
| 1308 | const our $ERROR_ILLEGAL_SASL_STATE => 34; | ||
| 1309 | |||
| 1310 | =item C<$ERROR_UNSUPPORTED_VERSION> | ||
| 1311 | |||
| 1312 | 35 - The version of API is not supported. | ||
| 1313 | |||
| 1314 | =cut | ||
| 1315 | const our $ERROR_UNSUPPORTED_VERSION => 35; | ||
| 1316 | |||
| 1317 | =item C<%ERROR> | ||
| 1318 | |||
| 1319 | Contains the descriptions for possible error codes. | ||
| 1320 | |||
| 1321 | =back | ||
| 1322 | |||
| 1323 | =cut | ||
| 1324 | our %ERROR = ( | ||
| 1325 | # Errors fixed by Kafka package | ||
| 1326 | $ERROR_MISMATCH_ARGUMENT => q{Invalid argument}, | ||
| 1327 | $ERROR_CANNOT_SEND => q{Cannot send}, | ||
| 1328 | $ERROR_SEND_NO_ACK => q{No acknowledgement for sent request}, | ||
| 1329 | $ERROR_CANNOT_RECV => q{Cannot receive}, | ||
| 1330 | $ERROR_CANNOT_BIND => q{Cannot connect to broker}, | ||
| 1331 | $ERROR_METADATA_ATTRIBUTES => q{Unknown metadata attributes}, | ||
| 1332 | $ERROR_UNKNOWN_APIKEY => q{Unknown ApiKey}, | ||
| 1333 | $ERROR_CANNOT_GET_METADATA => q{Cannot get metadata}, | ||
| 1334 | $ERROR_LEADER_NOT_FOUND => q{Leader not found}, | ||
| 1335 | $ERROR_MISMATCH_CORRELATIONID => q{Mismatch CorrelationId}, | ||
| 1336 | $ERROR_NO_KNOWN_BROKERS => q{There are no known brokers}, | ||
| 1337 | $ERROR_REQUEST_OR_RESPONSE => q{Bad request or response element}, | ||
| 1338 | $ERROR_TOPIC_DOES_NOT_MATCH => q{Topic does not match the requested}, | ||
| 1339 | $ERROR_PARTITION_DOES_NOT_MATCH => q{Partition does not match the requested}, | ||
| 1340 | $ERROR_NOT_BINARY_STRING => q{Not binary string}, | ||
| 1341 | $ERROR_COMPRESSION => q{Compression error}, | ||
| 1342 | $ERROR_RESPONSEMESSAGE_NOT_RECEIVED => q{'ResponseMessage' not received}, | ||
| 1343 | $ERROR_INCOMPATIBLE_HOST_IP_VERSION => q{'Incompatible host name and IP version'}, | ||
| 1344 | $ERROR_NO_CONNECTION => q{'No connection'}, | ||
| 1345 | $ERROR_GROUP_COORDINATOR_NOT_FOUND => q{'Group Coordinator Not Found'}, | ||
| 1346 | |||
| 1347 | #-- The Protocol Error Messages | ||
| 1348 | # https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-ErrorCodes | ||
| 1349 | $ERROR_NO_ERROR => q{}, # 'No error--it worked!', | ||
| 1350 | $ERROR_UNKNOWN => q{An unexpected server error}, | ||
| 1351 | $ERROR_OFFSET_OUT_OF_RANGE => q{The requested offset is outside the range of offsets maintained by the server for the given topic/partition}, | ||
| 1352 | $ERROR_INVALID_MESSAGE => q{Message contents does not match its CRC}, | ||
| 1353 | $ERROR_UNKNOWN_TOPIC_OR_PARTITION => q{Unknown topic or partition}, | ||
| 1354 | $ERROR_INVALID_FETCH_SIZE => q{The requested fetch size is invalid}, | ||
| 1355 | $ERROR_LEADER_NOT_AVAILABLE => q{Unable to write due to ongoing Kafka leader selection}, | ||
| 1356 | $ERROR_NOT_LEADER_FOR_PARTITION => q{Server is not a leader for partition}, | ||
| 1357 | $ERROR_REQUEST_TIMED_OUT => q{Request time-out}, | ||
| 1358 | $ERROR_BROKER_NOT_AVAILABLE => q{Broker is not available}, | ||
| 1359 | $ERROR_REPLICA_NOT_AVAILABLE => q{Replica not available}, | ||
| 1360 | $ERROR_MESSAGE_TOO_LARGE => q{Message is too big}, | ||
| 1361 | $ERROR_STALE_CONTROLLER_EPOCH => q{Stale Controller Epoch Code}, | ||
| 1362 | $ERROR_OFFSET_METADATA_TOO_LARGE => q{The metadata field of the offset request was too large}, | ||
| 1363 | $ERROR_NETWORK_EXCEPTION => q{The server disconnected before a response was received}, | ||
| 1364 | $ERROR_GROUP_LOAD_IN_PROGRESS => q{The coordinator is loading and hence can't process requests for this group}, | ||
| 1365 | $ERROR_GROUP_COORDINATOR_NOT_AVAILABLE => q{The group coordinator is not available.}, | ||
| 1366 | $ERROR_NOT_COORDINATOR_FOR_GROUP => q{Request for a group that it is not a coordinator for}, | ||
| 1367 | |||
| 1368 | $ERROR_INVALID_TOPIC_EXCEPTION => q{A request which attempts to access an invalid topic}, | ||
| 1369 | $ERROR_RECORD_LIST_TOO_LARGE => q{A message batch in a produce request exceeds the maximum configured segment size}, | ||
| 1370 | $ERROR_NOT_ENOUGH_REPLICAS => q{Messages are rejected since there are fewer in-sync replicas than required}, | ||
| 1371 | $ERROR_NOT_ENOUGH_REPLICAS_AFTER_APPEND => q{Messages are written to the log, but to fewer in-sync replicas than required}, | ||
| 1372 | $ERROR_INVALID_REQUIRED_ACKS => q{Produce request specified an invalid value for required acks}, | ||
| 1373 | $ERROR_ILLEGAL_GENERATION => q{Specified group generation id is not valid}, | ||
| 1374 | $ERROR_INCONSISTENT_GROUP_PROTOCOL => q{The group member's supported protocols are incompatible with those of existing members}, | ||
| 1375 | $ERROR_INVALID_GROUP_ID => q{The configured groupId is invalid}, | ||
| 1376 | $ERROR_UNKNOWN_MEMBER_ID => q{The coordinator is not aware of this member}, | ||
| 1377 | $ERROR_INVALID_SESSION_TIMEOUT => q{The session timeout is not within the range allowed by the broker}, | ||
| 1378 | $ERROR_REBALANCE_IN_PROGRESS => q{The group is rebalancing, so a rejoin is needed}, | ||
| 1379 | $ERROR_INVALID_COMMIT_OFFSET_SIZE => q{The committing offset data size is not valid}, | ||
| 1380 | $ERROR_TOPIC_AUTHORIZATION_FAILED => q{Not authorized to access topics}, | ||
| 1381 | $ERROR_GROUP_AUTHORIZATION_FAILED => q{Not authorized to access group: Group authorization failed}, | ||
| 1382 | $ERROR_CLUSTER_AUTHORIZATION_FAILED => q{Cluster authorization failed}, | ||
| 1383 | $ERROR_INVALID_TIMESTAMP => q{The timestamp of the message is out of acceptable range}, | ||
| 1384 | $ERROR_UNSUPPORTED_SASL_MECHANISM => q{The broker does not support the requested SASL mechanism}, | ||
| 1385 | $ERROR_ILLEGAL_SASL_STATE => q{Request is not valid given the current SASL state}, | ||
| 1386 | $ERROR_UNSUPPORTED_VERSION => q{The version of API is not supported}, | ||
| 1387 | ); | ||
| 1388 | |||
| 1389 | =over | ||
| 1390 | |||
| 1391 | =item C<BITS64> | ||
| 1392 | |||
| 1393 | Know you are working on 64 or 32 bit system | ||
| 1394 | |||
| 1395 | =back | ||
| 1396 | |||
| 1397 | =cut | ||
| 1398 | const our $BITS64 => ( defined( $Config{use64bitint} ) and $Config{use64bitint} eq 'define' ) || $Config{longsize} >= 8; | ||
| 1399 | |||
| 1400 | #-- public functions ----------------------------------------------------------- | ||
| 1401 | |||
| 1402 | #-- private functions ---------------------------------------------------------- | ||
| 1403 | |||
| 1404 | 1; | ||
| 1405 | |||
| 1406 | __END__ |