Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7379ed5

Browse files
committed
add libs
1 parent c25eb9a commit 7379ed5

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

‎docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
args:
88
PHP_IMAGE_TAG: 7.4-cli-alpine3.12
99
LIBRDKAFKA_VERSION: v1.5.0
10-
PHP_RDKAFKA_VERSION: 4.0.3
10+
PHP_RDKAFKA_VERSION: 4.0.4
1111
tty: true
1212
working_dir: /app
1313
volumes:

‎docker/php/Dockerfile.alpine

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ ARG PHP_RDKAFKA_VERSION
77

88
# Install packages
99
RUN apk --no-cache upgrade && \
10-
apk --no-cache add bash openssh sudo git gcc g++ make autoconf \
11-
icu libssl1.1 openssl-dev pcre-dev zlib-dev icu-dev wget gettext valgrind
10+
apk --no-cache add bash sudo git gcc g++ make autoconf \
11+
icu openssl-dev cyrus-sasl-dev pcre-dev zstd-dev lz4-dev zlib-dev icu-dev wget gettext valgrind
1212

1313
# Install librdkafka and ext-rdkafka
1414
RUN git clone --depth 1 --branch ${LIBRDKAFKA_VERSION} https://github.com/edenhill/librdkafka.git \

‎src/ext-php-rdkafka/php-kafka-lib/highLevelConsumer.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@
3838
)
3939
->withAdditionalBroker('kafka:9096')
4040
->withConsumerGroup('php-kafka-lib-high-level-consumer')
41-
->withSubscription('php-kafka-lib-test-topic')
41+
->withSubscription('pure-php-test-topic')
4242
->build();
4343

4444
$consumer->subscribe();
45-
45+
$c = 0;
4646
while (true) {
4747
try {
4848
$message = $consumer->consume(10000);
49+
++$c;
4950
} catch (KafkaConsumerTimeoutException|KafkaConsumerEndOfPartitionException $e) {
5051
echo 'Didn\'t receive any messages, waiting for more...' . PHP_EOL;
5152
continue;
@@ -54,15 +55,18 @@
5455
continue;
5556
}
5657

57-
echo sprintf(
58+
if($c%1000 === 0) {
59+
echo sprintf('%d messages consumed', $c) . PHP_EOL;
60+
}
61+
/*echo sprintf(
5862
'Read message with key:%s payload:%s topic:%s partition:%d offset:%d headers:%s',
5963
$message->getKey(),
6064
$message->getBody(),
6165
$message->getTopicName(),
6266
$message->getPartition(),
6367
$message->getOffset(),
6468
implode(',', $message->getHeaders())
65-
) . PHP_EOL;
69+
) . PHP_EOL;*/
6670

67-
$consumer->commit($message);
71+
//$consumer->commit($message);
6872
}

‎src/ext-php-rdkafka/pure-php/highLevelConsumer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838

3939
// Subscribe to one or multiple topics
4040
$consumer->subscribe(['pure-php-test-topic']);
41-
41+
$c = 0;
4242
while (true) {
4343
// Try to consume messages for the given timout (20s)
4444
$message = $consumer->consume(20000);
45+
$c++;
4546

4647
if (RD_KAFKA_RESP_ERR__PARTITION_EOF === $message->err) {
4748
echo 'Reached end of partition, waiting for more messages...' . PHP_EOL;
@@ -54,19 +55,23 @@
5455
continue;
5556
}
5657

57-
echo sprintf(
58+
if($c%1000 === 0) {
59+
echo sprintf('%d messages consumed', $c) . PHP_EOL;
60+
}
61+
62+
/*echo sprintf(
5863
'Read message with key:%s payload:%s topic:%s partition:%d offset:%d',
5964
$message->key,
6065
$message->payload,
6166
$message->topic_name,
6267
$message->partition,
6368
$message->offset
64-
) . PHP_EOL;
69+
) . PHP_EOL;*/
6570
// Here is where you do your business logic to process your message
6671
// after you have done so, commit the message offset to the broker
6772

6873
// commit the message(s) offset synchronous back to the broker
69-
$consumer->commit($message);
74+
//$consumer->commit($message);
7075

7176
// you can also commit the message(s) offset in an async manner, which is slightly faster
7277
// but poses of course the challenge of handling errors in an async manner as well

‎src/ext-php-rdkafka/pure-php/producer.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
$conf->set('compression.codec', 'snappy');
1717
// set timeout, producer will retry for 5s
1818
$conf->set('message.timeout.ms', '5000');
19+
$conf->set('linger.ms', '1000');
1920
//If you need to produce exactly once and want to keep the original produce order, uncomment the line below
2021
//$conf->set('enable.idempotence', 'true');
2122

@@ -28,7 +29,7 @@
2829
echo sprintf('Message FAILED (%s, %s) to send with payload => %s', $message->err, $errorStr, $message->payload) . PHP_EOL;
2930
} else {
3031
// message successfully delivered
31-
echo sprintf('Message sent SUCCESSFULLY with payload => %s', $message->payload) . PHP_EOL;
32+
//echo sprintf('Message sent SUCCESSFULLY with payload => %s', 'x') . PHP_EOL;
3233
}
3334
});
3435

@@ -57,7 +58,7 @@
5758
// initialize producer topic
5859
$topic = $producer->newTopic('pure-php-test-topic');
5960
// Produce 10 test messages
60-
$amountTestMessages = 10;
61+
$amountTestMessages = 1000000;
6162

6263
// Loop to produce some test messages
6364
for ($i = 0; $i < $amountTestMessages; ++$i) {
@@ -69,13 +70,19 @@
6970
$topic->producev(
7071
$partition,
7172
RD_KAFKA_MSG_F_BLOCK, // will block produce if queue is full
72-
sprintf('test message-%d',$i),
73+
//sprintf('test message-%d',$i),
74+
str_repeat('12312313123213123',10000),
7375
sprintf('test-key-%d', $i),
7476
[
7577
'some' => sprintf('header value %d', $i)
7678
]
7779
);
78-
echo sprintf('Queued message number: %d', $i) . PHP_EOL;
80+
if ($i%1000 === 0) {
81+
echo sprintf('Queued message number: %d', $i) . PHP_EOL;
82+
}
83+
if ($i%5000 === 0) {
84+
$producer->flush(10000);
85+
}
7986

8087
// Poll for events e.g. producer callbacks, to handle errors, etc.
8188
// 0 = non-blocking

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /