Skip to content

Commit

Permalink
ci: use optional LIBRDKAFKA_LIBRARY_PATH in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dirx committed Oct 28, 2024
1 parent d2576c2 commit d5aebf8
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 11 deletions.
12 changes: 12 additions & 0 deletions examples/_init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use RdKafka\FFI\Library;

// use custom librdkafka library path
Library::init(
Library::VERSION_AUTODETECT,
'RdKafka',
getenv('LIBRDKAFKA_LIBRARY_PATH') ?: null
);
1 change: 1 addition & 0 deletions examples/binding.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use RdKafka\FFI\Library;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

echo 'has method rd_kafka_conf_new:' . PHP_EOL;
var_dump(Library::hasMethod('rd_kafka_conf_new'));
Expand Down
1 change: 1 addition & 0 deletions examples/consumer-highlevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use RdKafka\KafkaConsumer;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

$conf = new Conf();
$conf->set('bootstrap.servers', 'kafka:9092');
Expand Down
5 changes: 3 additions & 2 deletions examples/consumer-lowlevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use RdKafka\TopicConf;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

$conf = new Conf();
$conf->set('bootstrap.servers', 'kafka:9092');
Expand All @@ -19,7 +20,7 @@ function (Consumer $consumer, int $level, string $facility, string $message): vo
}
);

$conf->set('statistics.interval.ms', (string) 1000);
$conf->set('statistics.interval.ms', (string)1000);
$conf->setStatsCb(
function (Consumer $consumer, string $json, int $jsonLength, $opaque): void {
echo "stats: ${json}" . PHP_EOL;
Expand All @@ -28,7 +29,7 @@ function (Consumer $consumer, string $json, int $jsonLength, $opaque): void {

$topicConf = new TopicConf();
$topicConf->set('enable.auto.commit', 'true');
$topicConf->set('auto.commit.interval.ms', (string) 100);
$topicConf->set('auto.commit.interval.ms', (string)100);
$topicConf->set('auto.offset.reset', 'earliest');
var_dump($topicConf->dump());

Expand Down
9 changes: 5 additions & 4 deletions examples/create-topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use RdKafka\Conf;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

$options = array_merge(
[
Expand All @@ -28,16 +29,16 @@
$conf = new Conf();
$conf->set('bootstrap.servers', $options['b']);
$client = Client::fromConf($conf);
$client->setWaitForResultEventTimeout((int) $options['w']);
$client->setWaitForResultEventTimeout((int)$options['w']);
$partitions = $options['p'];
$replicationFactor = $options['r'];

$results = $client->createTopics(
[
new NewTopic(
(string) $options['t'],
(int) $partitions,
(int) $replicationFactor
(string)$options['t'],
(int)$partitions,
(int)$replicationFactor
),
]
);
Expand Down
5 changes: 3 additions & 2 deletions examples/delete-topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use RdKafka\Conf;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

$options = array_merge(
[
Expand All @@ -26,12 +27,12 @@
$conf = new Conf();
$conf->set('bootstrap.servers', $options['b']);
$client = Client::fromConf($conf);
$client->setWaitForResultEventTimeout((int) $options['w']);
$client->setWaitForResultEventTimeout((int)$options['w']);

$results = $client->deleteTopics(
[
new DeleteTopic(
(string) $options['t']
(string)$options['t']
),
]
);
Expand Down
3 changes: 2 additions & 1 deletion examples/describe-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use RdKafka\Conf;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

$options = array_merge(
[
Expand All @@ -31,7 +32,7 @@

$results = $client->describeConfigs(
[
new ConfigResource((int) $options['t'], (string) $options['v']),
new ConfigResource((int)$options['t'], (string)$options['v']),
]
);

Expand Down
2 changes: 2 additions & 0 deletions examples/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
declare(strict_types=1);

use RdKafka\Conf;
use RdKafka\FFI\Library;
use RdKafka\Producer;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

$conf = new Conf();
$conf->set('group.id', 'metadata');
Expand Down
1 change: 1 addition & 0 deletions examples/mock-cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use RdKafka\TopicPartition;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

$clusterConf = new Conf();
$clusterConf->set('log_level', (string) LOG_DEBUG);
Expand Down
2 changes: 2 additions & 0 deletions examples/offset-lags.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
$composerLoader = require_once dirname(__DIR__) . '/vendor/autoload.php';
$composerLoader->addPsr4('RdKafka\\Examples\\', __DIR__);

include '_init.php';

$conf = new Conf();
$conf->set('bootstrap.servers', 'kafka:9092');
$conf->set('group.id', 'consumer-offsets.dev');
Expand Down
7 changes: 6 additions & 1 deletion examples/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use RdKafka\FFI\Library;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

$files = new RegexIterator(
new RecursiveIteratorIterator(
Expand All @@ -22,4 +23,8 @@
require_once($file->getPathName());
}

Library::preload();
Library::preload(
Library::VERSION_AUTODETECT,
'RdKafka',
getenv('LIBRDKAFKA_LIBRARY_PATH') ?? null
);
1 change: 1 addition & 0 deletions examples/producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use RdKafka\TopicConf;

require_once dirname(__DIR__) . '/vendor/autoload.php';
include '_init.php';

$conf = new Conf();
$conf->set('bootstrap.servers', 'kafka:9092');
Expand Down
6 changes: 5 additions & 1 deletion examples/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
$version = getenv('LIBRDKAFKA_VERSION') ?: '';
$version = ltrim($version, 'v');
$version = $version === 'master' ? Library::VERSION_LATEST : $version;
Library::init($version);
Library::init(
$version,
'RdKafka',
getenv('LIBRDKAFKA_LIBRARY_PATH') ?: null
);

echo 'Binding version (string) : ' . Library::getVersion() . PHP_EOL;
echo 'librdkafka version (int) : ' . Library::rd_kafka_version() . PHP_EOL;
Expand Down

0 comments on commit d5aebf8

Please sign in to comment.