|
| 1 | +<?php |
| 2 | + |
| 3 | +use SimpleKafkaClient\Configuration; |
| 4 | +use SimpleKafkaClient\Message; |
| 5 | +use SimpleKafkaClient\Consumer; |
| 6 | +use SimpleKafkaClient\Producer; |
| 7 | +use SimpleKafkaClient\TopicPartition; |
| 8 | + |
| 9 | +error_reporting(E_ALL); |
| 10 | + |
| 11 | +$conf = new Configuration(); |
| 12 | +$conf->set('client.id', 'pure-php-producer'); |
| 13 | +$conf->set('metadata.broker.list', 'kafka:9096'); |
| 14 | +$conf->set('compression.codec', 'snappy'); |
| 15 | +$conf->set('message.timeout.ms', '5000'); |
| 16 | + |
| 17 | +$producer = new Producer($conf); |
| 18 | +$topic = $producer->getTopicHandle('pure-php-test-topic-watermark'); |
| 19 | +$time = time(); |
| 20 | +$topic->producev( |
| 21 | + RD_KAFKA_PARTITION_UA, |
| 22 | + RD_KAFKA_MSG_F_BLOCK, // will block produce if queue is full |
| 23 | + 'special-message', |
| 24 | + 'special-key', |
| 25 | + [ |
| 26 | + 'special-header' => 'awesome' |
| 27 | + ] |
| 28 | +); |
| 29 | +$result = $producer->flush(20000); |
| 30 | +$high = 0; |
| 31 | +$low = 0; |
| 32 | +$result = $producer->queryWatermarkOffsets('pure-php-test-topic-watermark', 0,$low, $high, 10000); |
| 33 | + |
| 34 | +echo sprintf('Lowest offset is: %d, highest offset is: %d', $low, $high) . PHP_EOL; |
| 35 | + |
0 commit comments