|
| 1 | +--TEST-- |
| 2 | +Bug 508 |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +require __DIR__ . '/integration-tests-check.php'; |
| 6 | +--FILE-- |
| 7 | +<?php |
| 8 | +require __DIR__ . '/integration-tests-check.php'; |
| 9 | + |
| 10 | +$topicName = sprintf("test_rdkafka_%s", uniqid()); |
| 11 | + |
| 12 | +$conf = new RdKafka\Conf(); |
| 13 | +$conf->set('metadata.broker.list', getenv('TEST_KAFKA_BROKERS')); |
| 14 | +$conf->setDrMsgCb(function ($producer, $msg) use (&$delivered) { |
| 15 | + if ($msg->err) { |
| 16 | + throw new Exception("Message delivery failed: " . $msg->errstr()); |
| 17 | + } |
| 18 | + $delivered++; |
| 19 | +}); |
| 20 | + |
| 21 | +$producer = new RdKafka\Producer($conf); |
| 22 | +$topic = $producer->newTopic($topicName); |
| 23 | + |
| 24 | +if (!$producer->getMetadata(false, $topic, 10*1000)) { |
| 25 | + echo "Failed to get metadata, is broker down?\n"; |
| 26 | +} |
| 27 | + |
| 28 | +$topic->produce(0, 0, "message"); |
| 29 | + |
| 30 | +while ($producer->getOutQLen()) { |
| 31 | + $producer->poll(50); |
| 32 | +} |
| 33 | + |
| 34 | +printf("%d messages delivered\n", $delivered); |
| 35 | + |
| 36 | +$conf = new RdKafka\Conf(); |
| 37 | +$conf->set('metadata.broker.list', getenv('TEST_KAFKA_BROKERS')); |
| 38 | +$conf->set('enable.partition.eof', 'true'); |
| 39 | + |
| 40 | +$consumer = new RdKafka\Consumer($conf); |
| 41 | +$topic = $consumer->newTopic($topicName); |
| 42 | +$topic->consumeStart(0, RD_KAFKA_OFFSET_BEGINNING); |
| 43 | + |
| 44 | +while (true) { |
| 45 | + $msg = $topic->consume(0, 1000); |
| 46 | + if (!$msg) { |
| 47 | + continue; |
| 48 | + } |
| 49 | + // All props are initialized and readable in all cases |
| 50 | + var_dump([ |
| 51 | + 'err' => $msg->err, |
| 52 | + 'topic_name' => $msg->topic_name, |
| 53 | + 'timestamp' => $msg->timestamp, |
| 54 | + 'partition' => $msg->partition, |
| 55 | + 'payload' => $msg->payload, |
| 56 | + 'len' => $msg->len, |
| 57 | + 'key' => $msg->key, |
| 58 | + 'offset' => $msg->offset, |
| 59 | + 'headers' => $msg->headers, |
| 60 | + 'opaque' => $msg->opaque, |
| 61 | + ]); |
| 62 | + echo "--------------\n"; |
| 63 | + if ($msg->err === RD_KAFKA_RESP_ERR__PARTITION_EOF) { |
| 64 | + echo "EOF\n"; |
| 65 | + break; |
| 66 | + } |
| 67 | +} |
| 68 | +--EXPECTF-- |
| 69 | +1 messages delivered |
| 70 | +array(10) { |
| 71 | + ["err"]=> |
| 72 | + int(0) |
| 73 | + ["topic_name"]=> |
| 74 | + string(%d) "test_rdkafka_%s" |
| 75 | + ["timestamp"]=> |
| 76 | + int(%d) |
| 77 | + ["partition"]=> |
| 78 | + int(0) |
| 79 | + ["payload"]=> |
| 80 | + string(7) "message" |
| 81 | + ["len"]=> |
| 82 | + int(7) |
| 83 | + ["key"]=> |
| 84 | + NULL |
| 85 | + ["offset"]=> |
| 86 | + int(0) |
| 87 | + ["headers"]=> |
| 88 | + array(0) { |
| 89 | + } |
| 90 | + ["opaque"]=> |
| 91 | + NULL |
| 92 | +} |
| 93 | +-------------- |
| 94 | +array(10) { |
| 95 | + ["err"]=> |
| 96 | + int(-%d) |
| 97 | + ["topic_name"]=> |
| 98 | + string(%d) "test_rdkafka_%s" |
| 99 | + ["timestamp"]=> |
| 100 | + int(-1) |
| 101 | + ["partition"]=> |
| 102 | + int(0) |
| 103 | + ["payload"]=> |
| 104 | + string(%d) "%s" |
| 105 | + ["len"]=> |
| 106 | + int(%d) |
| 107 | + ["key"]=> |
| 108 | + NULL |
| 109 | + ["offset"]=> |
| 110 | + int(1) |
| 111 | + ["headers"]=> |
| 112 | + array(0) { |
| 113 | + } |
| 114 | + ["opaque"]=> |
| 115 | + NULL |
| 116 | +} |
| 117 | +-------------- |
| 118 | +EOF |
0 commit comments