public function testEncodedMessages() { $topic = 'sample topic'; $partition = 1; $messages = array('test 1', 'test 2 abcde'); $encoded = Kafka_Encoder::encode_produce_request($topic, $partition, $messages); $this->assertContains($topic, $encoded); $this->assertContains($partition, $encoded); foreach ($messages as $msg) { $this->assertContains($msg, $encoded); } $size = 4 + 2 + 2 + strlen($topic) + 4 + 4; foreach ($messages as $msg) { $size += 9 + strlen($msg); } $this->assertEquals($size, strlen($encoded)); }
/** * Get the message payload * * @return string|Kafka_MessageSetInternalIterator */ public function payload() { return Kafka_Encoder::decompress($this->payload, $this->compression); }
/** * 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 = 4294967295.0) { if ($this->connect()) { return fwrite($this->conn, Kafka_Encoder::encode_produce_request($topic, $partition, $messages, $this->compression)); } }
/** * 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 = 0) { $this->connect(); return fwrite($this->conn, Kafka_Encoder::encode_produce_request($topic, $partition, $messages)); }
/** * 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)); }
private function writeDummyCompressedMessageSet($stream, array $messages, $compression) { $encoded = Kafka_Encoder::encode_message($this->getMessageSetBuffer($messages), $compression); return fwrite($stream, pack('N', strlen($encoded)) . $encoded); }
public function setUp() { $this->test = 'a sample string'; $this->encoded = Kafka_Encoder::encode_message($this->test); $this->msg = new Kafka_Message($this->encoded); }
/** * @expectedException Kafka_Exception_NotSupported */ public function testDecompressUnknown() { $msg = 'test message'; Kafka_Encoder::decompress($msg, 15); $this->fail('The above call should fail'); }
/** * Encode a message * * @return string */ public function encode() { return Kafka_Encoder::encode_message($this->payload); }