Exemple #1
0
 /**
  * Write the Request Header
  * <req_len> + <req_type> + <topic_len> + <topic> + <partition>
  *
  * @param Kafka_Socket $socket Socket
  *
  * @return void
  */
 protected function writeRequestHeader(Kafka_Socket $socket)
 {
     // REQUEST_LENGTH (int) + REQUEST_TYPE (short)
     $socket->write(pack('N', $this->sizeInBytes() + 2));
     $socket->write(pack('n', $this->id));
     // TOPIC_SIZE (short) + TOPIC (bytes)
     $socket->write(pack('n', strlen($this->topic)) . $this->topic);
     // PARTITION (int)
     $socket->write(pack('N', $this->partition));
 }
Exemple #2
0
 /**
  * @expectedException Kafka_Exception_Socket_Timeout
  */
 public function testWriteTimeout()
 {
     $this->markTestSkipped('find a better way of testing socket timeouts');
     $stream = fopen('php://temp', 'w+b');
     $socket = new Kafka_Socket('localhost', 0, 0, 0, -1, -1);
     $socket->setStream($stream);
     $socket->write('short timeout');
     //$socket->rewind();
     //var_dump($socket->read(4));
     $this->fail('The above write() call should fail on a socket with timeout = -1');
 }
Exemple #3
0
 /**
  * Send messages to Kafka
  * 
  * @param array   $messages  Messages to send
  * @param string  $topic     Topic
  * @param integer $partition Partition
  *
  * @return boolean
  */
 public function send(array $messages, $topic, $partition = 0xffffffff)
 {
     $this->connect();
     return $this->socket->write(Kafka_Encoder::encode_produce_request($topic, $partition, $messages, $this->compression));
 }