Skip to content

Commit d5aebf8

Browse files
committed
ci: use optional LIBRDKAFKA_LIBRARY_PATH in examples
1 parent d2576c2 commit d5aebf8

13 files changed

+44
-11
lines changed

examples/_init.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use RdKafka\FFI\Library;
6+
7+
// use custom librdkafka library path
8+
Library::init(
9+
Library::VERSION_AUTODETECT,
10+
'RdKafka',
11+
getenv('LIBRDKAFKA_LIBRARY_PATH') ?: null
12+
);

examples/binding.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use RdKafka\FFI\Library;
66

77
require_once dirname(__DIR__) . '/vendor/autoload.php';
8+
include '_init.php';
89

910
echo 'has method rd_kafka_conf_new:' . PHP_EOL;
1011
var_dump(Library::hasMethod('rd_kafka_conf_new'));

examples/consumer-highlevel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use RdKafka\KafkaConsumer;
77

88
require_once dirname(__DIR__) . '/vendor/autoload.php';
9+
include '_init.php';
910

1011
$conf = new Conf();
1112
$conf->set('bootstrap.servers', 'kafka:9092');

examples/consumer-lowlevel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RdKafka\TopicConf;
88

99
require_once dirname(__DIR__) . '/vendor/autoload.php';
10+
include '_init.php';
1011

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

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

2930
$topicConf = new TopicConf();
3031
$topicConf->set('enable.auto.commit', 'true');
31-
$topicConf->set('auto.commit.interval.ms', (string) 100);
32+
$topicConf->set('auto.commit.interval.ms', (string)100);
3233
$topicConf->set('auto.offset.reset', 'earliest');
3334
var_dump($topicConf->dump());
3435

examples/create-topic.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RdKafka\Conf;
88

99
require_once dirname(__DIR__) . '/vendor/autoload.php';
10+
include '_init.php';
1011

1112
$options = array_merge(
1213
[
@@ -28,16 +29,16 @@
2829
$conf = new Conf();
2930
$conf->set('bootstrap.servers', $options['b']);
3031
$client = Client::fromConf($conf);
31-
$client->setWaitForResultEventTimeout((int) $options['w']);
32+
$client->setWaitForResultEventTimeout((int)$options['w']);
3233
$partitions = $options['p'];
3334
$replicationFactor = $options['r'];
3435

3536
$results = $client->createTopics(
3637
[
3738
new NewTopic(
38-
(string) $options['t'],
39-
(int) $partitions,
40-
(int) $replicationFactor
39+
(string)$options['t'],
40+
(int)$partitions,
41+
(int)$replicationFactor
4142
),
4243
]
4344
);

examples/delete-topic.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RdKafka\Conf;
88

99
require_once dirname(__DIR__) . '/vendor/autoload.php';
10+
include '_init.php';
1011

1112
$options = array_merge(
1213
[
@@ -26,12 +27,12 @@
2627
$conf = new Conf();
2728
$conf->set('bootstrap.servers', $options['b']);
2829
$client = Client::fromConf($conf);
29-
$client->setWaitForResultEventTimeout((int) $options['w']);
30+
$client->setWaitForResultEventTimeout((int)$options['w']);
3031

3132
$results = $client->deleteTopics(
3233
[
3334
new DeleteTopic(
34-
(string) $options['t']
35+
(string)$options['t']
3536
),
3637
]
3738
);

examples/describe-config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RdKafka\Conf;
88

99
require_once dirname(__DIR__) . '/vendor/autoload.php';
10+
include '_init.php';
1011

1112
$options = array_merge(
1213
[
@@ -31,7 +32,7 @@
3132

3233
$results = $client->describeConfigs(
3334
[
34-
new ConfigResource((int) $options['t'], (string) $options['v']),
35+
new ConfigResource((int)$options['t'], (string)$options['v']),
3536
]
3637
);
3738

examples/metadata.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
declare(strict_types=1);
44

55
use RdKafka\Conf;
6+
use RdKafka\FFI\Library;
67
use RdKafka\Producer;
78

89
require_once dirname(__DIR__) . '/vendor/autoload.php';
10+
include '_init.php';
911

1012
$conf = new Conf();
1113
$conf->set('group.id', 'metadata');

examples/mock-cluster.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use RdKafka\TopicPartition;
1414

1515
require_once dirname(__DIR__) . '/vendor/autoload.php';
16+
include '_init.php';
1617

1718
$clusterConf = new Conf();
1819
$clusterConf->set('log_level', (string) LOG_DEBUG);

examples/offset-lags.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
$composerLoader = require_once dirname(__DIR__) . '/vendor/autoload.php';
3838
$composerLoader->addPsr4('RdKafka\\Examples\\', __DIR__);
3939

40+
include '_init.php';
41+
4042
$conf = new Conf();
4143
$conf->set('bootstrap.servers', 'kafka:9092');
4244
$conf->set('group.id', 'consumer-offsets.dev');

0 commit comments

Comments
 (0)