Пример #1
0
<?php

require 'autoloader.php';
$data = array('group_id' => 'testgroup1', 'data' => array(array('topic_name' => 'test6', 'partitions' => array(array('partition_id' => 2, 'offset' => 2)))));
$conn = new \Kafka\Socket('hadoop11', '9092');
$conn->connect();
$encoder = new \Kafka\Protocol\Encoder($conn);
$encoder->commitOffsetRequest($data);
$decoder = new \Kafka\Protocol\Decoder($conn);
$result = $decoder->commitOffsetResponse();
var_dump($result);
Пример #2
0
 /**
  * testCommitOffsetRequest
  *
  * @access public
  * @return void
  */
 public function testCommitOffsetRequest()
 {
     $encoder = new \Kafka\Protocol\Encoder($this->stream);
     $data = array();
     try {
         $encoder->commitOffsetRequest($data);
     } catch (\Kafka\Exception\Protocol $e) {
         $this->assertSame('given commit offset data invalid. `data` is undefined.', $e->getMessage());
     }
     $data = array('data' => array(array('topic_name' => 'debug', 'partitions' => array())));
     try {
         $encoder->commitOffsetRequest($data);
     } catch (\Kafka\Exception\Protocol $e) {
         $this->assertSame('given commit offset data invalid. `group_id` is undefined.', $e->getMessage());
     }
     $data = array('group_id' => 'testgroup', 'data' => array(array('topic_name' => 'debug', 'partitions' => array(array('partition_id' => 1, 'offset' => 2)))));
     $len = $encoder->commitOffsetRequest($data);
     $this->assertEquals('00000044000800000000000000096b61666b612d70687000097465737467726f7570000000010005646562756700000001000000010000000000000002ffffffffffffffff00016d', $this->getData($len));
 }