Skip to content

Commit 0cc0109

Browse files
authored
Restructure (#3)
* update docker files * save work on restructure * save work on restructure * save work on restructure * adjust templates
1 parent 3f742e4 commit 0cc0109

32 files changed

+681
-53
lines changed

Diff for: .gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/vendor/
1+
**/vendor/
22
/.idea
33
/keys
4-
composer.lock
4+
**/composer.lock
5+
**/*.iml
56
src/jc
67
docker-compose.jc.yml

Diff for: README.md

+9-14
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,22 @@
22
This repository has PHP examples for Kafka consumers / producers for:
33
- [php-rdkafka](https://github.com/arnaud-lb/php-rdkafka): Examples just using the PHP extension
44
- [php-kafka-lib](https://github.com/jobcloud/php-kafka-lib): PHP library that relies on [php-rdkafka](https://github.com/arnaud-lb/php-rdkafka) and supports [avro](https://github.com/flix-tech/avro-serde-php)
5+
- [php-simple-kafka-client](https://github.com/php-kafka/php-simple-kafka-client): Examples just using the PHP extension
6+
- [php-simple-kafka-lib](https://github.com/php-kafka/php-simple-kafka-lib): PHP library that relies on [php-simple-kafka-client](https://github.com/php-kafka/php-simple-kafka-client) and supports [avro](https://github.com/flix-tech/avro-serde-php)
57

68
## Examples
7-
- [php-rdkafka](src/ext-php-rdkafka/pure-php)
8-
- [php-kafka-lib](src/ext-php-rdkafka/php-kafka-lib)
9-
10-
## Start containers for examples
11-
Be sure to start the docker containers.
12-
To do so, run this in the project root:
13-
```bash
14-
docker-compose up -d
15-
docker-compose exec php bash
16-
```
17-
Then follow the instructions in the example folders.
9+
Checkout these folders to see how to run the examples:
10+
- [php-rdkafka](src/ext-php-rdkafka)
11+
- [php-simple-kafka-client](src/ext-php-simple-kafka-client)
1812

1913
## Customize to fit your setup
2014
If you wan't to test / debug something that is closer to your setup,
2115
you can modify the following arguments in `docker-compose.yml`:
2216
```
23-
PHP_IMAGE_TAG: 7.4-cli-alpine3.11
24-
LIBRDKAFKA_VERSION: v1.4.0
25-
PHP_RDKAFKA_VERSION: 4.0.3
17+
PHP_IMAGE_TAG: 8.0-cli-alpine3.13
18+
LIBRDKAFKA_VERSION: v1.6.1
19+
PHP_EXTENSION: php-kafka/php-simple-kafka-client
20+
PHP_EXTENSION_VERSION: v0.1.1
2621
```
2722
Adjust those, to reflect your setup and afterwards run:
2823
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3.7'
2+
services:
3+
php:
4+
build:
5+
context: ../php
6+
dockerfile: Dockerfile.alpine
7+
args:
8+
PHP_IMAGE_TAG: 8.0-cli-alpine3.13
9+
LIBRDKAFKA_VERSION: v1.6.1
10+
PHP_EXTENSION: arnaud-lb/php-rdkafka
11+
PHP_EXTENSION_VERSION: 5.0.0
12+
tty: true
13+
working_dir: /app
14+
volumes:
15+
- ./:/app
16+
redpanda:
17+
entrypoint:
18+
- /usr/bin/rpk
19+
- redpanda
20+
- start
21+
- --smp
22+
- '1'
23+
- --reserve-memory
24+
- 0M
25+
- --overprovisioned
26+
- --node-id
27+
- '0'
28+
- --check=false
29+
image: vectorized/redpanda:v21.4.7
30+
ports:
31+
- 9092:9092
32+
- 29092:29092
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
version: '3.7'
2+
services:
3+
php:
4+
build:
5+
context: ../php
6+
dockerfile: Dockerfile.alpine
7+
args:
8+
PHP_IMAGE_TAG: 8.0-cli-alpine3.13
9+
LIBRDKAFKA_VERSION: v1.6.1
10+
PHP_EXTENSION: php-kafka/php-simple-kafka-client
11+
PHP_EXTENSION_VERSION: v0.1.1
12+
tty: true
13+
working_dir: /app
14+
volumes:
15+
- ./:/app
16+
17+
zookeeper:
18+
image: confluentinc/cp-zookeeper:6.1.1
19+
environment:
20+
ZOOKEEPER_CLIENT_PORT: 2182
21+
ZOOKEEPER_TICK_TIME: 2000
22+
23+
kafka:
24+
image: confluentinc/cp-kafka:6.1.1
25+
depends_on:
26+
- zookeeper
27+
ports:
28+
- 9096:9096
29+
environment:
30+
KAFKA_BROKER_ID: 1
31+
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2182'
32+
KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:9096'
33+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
34+
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
35+
KAFKA_NUM_PARTITIONS: 1
36+
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
37+
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
38+
39+
kafka-schema-registry:
40+
image: confluentinc/cp-schema-registry:6.1.1
41+
depends_on:
42+
- zookeeper
43+
- kafka
44+
ports:
45+
- "9083:9083"
46+
environment:
47+
SCHEMA_REGISTRY_HOST_NAME: kafka-schema-registry
48+
SCHEMA_REGISTRY_LISTENERS: "http://0.0.0.0:9083"
49+
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: 'zookeeper:2182'
50+
SCHEMA_REGISTRY_AVRO_COMPATIBILITY_LEVEL: 'full_transitive'

Diff for: docker-compose.centos.yml renamed to docker/docker-compose-templates/docker-compose.centos.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ version: '3.7'
22
services:
33
php:
44
build:
5-
context: ./docker/php
6-
dockerfile: Dockerfile.centos
5+
context: ../php
6+
dockerfile: ../php/Dockerfile.centos
77
args:
88
CENTOS_VERSION: 7
99
PHP_VERSION: 74

Diff for: docker-compose.debug.yml renamed to docker/docker-compose-templates/docker-compose.debug.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ version: '3.7'
22
services:
33
php:
44
build:
5-
context: ./docker/php
6-
dockerfile: Dockerfile.debug
5+
context: ../php
6+
dockerfile: ../php/Dockerfile.debug
77
args:
88
PHP_VERSION: 7.4.14
99
LIBRDKAFKA_VERSION: v1.5.3
10-
PHP_RDKAFKA_VERSION: 5.x
10+
PHP_RDKAFKA_VERSION: 5.0.0
1111
tty: true
1212
working_dir: /app
1313
volumes:

Diff for: docker-compose.master.yml renamed to docker/docker-compose-templates/docker-compose.master.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ version: '3.7'
22
services:
33
php:
44
build:
5-
context: ./docker/php
6-
dockerfile: Dockerfile.master
5+
context: ../php
6+
dockerfile: ../php/Dockerfile.master
77
args:
88
LIBRDKAFKA_VERSION: v1.5.0
99
tty: true

Diff for: docker/php/Dockerfile.alpine

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ ARG PHP_IMAGE_TAG
33
FROM php:${PHP_IMAGE_TAG}
44

55
ARG LIBRDKAFKA_VERSION
6-
ARG PHP_RDKAFKA_VERSION
6+
ARG PHP_EXTENSION
7+
ARG PHP_EXTENSION_VERSION
8+
9+
710

811
# Install packages
912
RUN apk --no-cache upgrade && \
@@ -16,8 +19,8 @@ RUN git clone --depth 1 --branch ${LIBRDKAFKA_VERSION} https://github.com/edenhi
1619
&& ./configure \
1720
&& make \
1821
&& make install \
19-
&& git clone --depth 1 --branch ${PHP_RDKAFKA_VERSION} https://github.com/arnaud-lb/php-rdkafka.git \
20-
&& cd php-rdkafka \
22+
&& git clone --depth 1 --branch ${PHP_EXTENSION_VERSION} https://github.com/${PHP_EXTENSION}.git \
23+
&& cd $(basename ${PHP_EXTENSION}) \
2124
&& phpize \
2225
&& ./configure \
2326
&& make all -j 5 \
@@ -26,7 +29,11 @@ RUN git clone --depth 1 --branch ${LIBRDKAFKA_VERSION} https://github.com/edenhi
2629

2730
# Install php extensions
2831
RUN docker-php-ext-install pcntl && \
29-
docker-php-ext-enable rdkafka pcntl > /dev/null 2>&1
32+
if [ ${PHP_EXTENSION} = "arnaud-lb/php-rdkafka" ]; then \
33+
docker-php-ext-enable rdkafka pcntl > /dev/null 2>&1; \
34+
else \
35+
docker-php-ext-enable simple_kafka_client pcntl > /dev/null 2>&1; \
36+
fi
3037

3138
# Install composer
3239
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

Diff for: src/ext-php-rdkafka/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Running the examples
2+
1. `docker-compose up -d`
3+
2. `docker-compose exec php composer update`
4+
3. Check the subfolders on how to run the examples
File renamed without changes.

Diff for: docker-compose.yml renamed to src/ext-php-rdkafka/docker-compose.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@ version: '3.7'
22
services:
33
php:
44
build:
5-
context: ./docker/php
5+
context: ../../docker/php
66
dockerfile: Dockerfile.alpine
77
args:
8-
PHP_IMAGE_TAG: 7.4-cli-alpine3.12
9-
LIBRDKAFKA_VERSION: v1.5.0
10-
PHP_RDKAFKA_VERSION: 4.0.4
8+
PHP_IMAGE_TAG: 8.0-cli-alpine3.13
9+
LIBRDKAFKA_VERSION: v1.6.1
10+
PHP_EXTENSION: arnaud-lb/php-rdkafka
11+
PHP_EXTENSION_VERSION: 5.0.0
1112
tty: true
1213
working_dir: /app
1314
volumes:
1415
- ./:/app
1516

1617
zookeeper:
17-
image: confluentinc/cp-zookeeper:5.5.0
18+
image: confluentinc/cp-zookeeper:6.1.1
1819
environment:
1920
ZOOKEEPER_CLIENT_PORT: 2182
2021
ZOOKEEPER_TICK_TIME: 2000
2122

2223
kafka:
23-
image: confluentinc/cp-kafka:5.5.0
24+
image: confluentinc/cp-kafka:6.1.1
2425
depends_on:
2526
- zookeeper
2627
ports:
@@ -36,7 +37,7 @@ services:
3637
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
3738

3839
kafka-schema-registry:
39-
image: confluentinc/cp-schema-registry:5.5.0
40+
image: confluentinc/cp-schema-registry:6.1.1
4041
depends_on:
4142
- zookeeper
4243
- kafka

Diff for: src/ext-php-rdkafka/php-kafka-lib/README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
# Register test schema
22
Run the following to register the test schema:
33
```bash
4-
cd src/ext-php-rdkafka/php-kafka-lib
4+
cd php-kafka-lib
55
./console kafka-schema-registry:register:changed avroSchema
66
```
77

88
# Running consumer / producer
99
## Prerequisites
10-
Be sure to do this first: [Start containers](./../../../README.md#start-containers-for-examples)
11-
and to also have registered the test schema (see above).
10+
Be sure to do this first: [Start containers](./../README.md)
11+
Connect to the php container:
12+
```bash
13+
docker-compose exec php bash
14+
```
1215

1316
## Avro producer
1417
Will per default produce 10 avro messages:
1518
```bash
1619
php avroProducer.php
1720
```
1821

19-
## Avro high level consumer
22+
## Avro consumer
2023
Will consume all messages available:
2124
```bash
22-
php avroHighLevelConsumer.php
25+
php avroConsumer.php
2326
```
2427

2528
## Producer
@@ -28,8 +31,8 @@ Will per default produce 10 messages:
2831
php producer.php
2932
```
3033

31-
## High level consumer
34+
## Consumer
3235
Will consume all messages available:
3336
```bash
34-
php highLevelConsumer.php
37+
php consumer.php
3538
```

Diff for: src/ext-php-rdkafka/php-kafka-lib/avroHighLevelConsumer.php renamed to src/ext-php-rdkafka/php-kafka-lib/avroConsumer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require_once('../../../vendor/autoload.php');
3+
require_once('../vendor/autoload.php');
44

55
use FlixTech\AvroSerializer\Objects\RecordSerializer;
66
use FlixTech\SchemaRegistryApi\Exception\SchemaNotFoundException;

Diff for: src/ext-php-rdkafka/php-kafka-lib/avroProducer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require_once('../../../vendor/autoload.php');
3+
require_once('../vendor/autoload.php');
44

55
use FlixTech\AvroSerializer\Objects\RecordSerializer;
66
use FlixTech\SchemaRegistryApi\Registry\BlockingRegistry;

Diff for: src/ext-php-rdkafka/php-kafka-lib/console

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare(strict_types=1);
44

55
namespace Jobcloud\Message\Schema;
66

7-
include_once __DIR__ . '/../../../vendor/autoload.php';
7+
include_once __DIR__ . '/../vendor/autoload.php';
88

99
use Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider\KafkaSchemaRegistryApiClientProvider;
1010
use Symfony\Component\Console\Application;

Diff for: src/ext-php-rdkafka/php-kafka-lib/highLevelConsumer.php renamed to src/ext-php-rdkafka/php-kafka-lib/consumer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require_once('../../../vendor/autoload.php');
3+
require_once('../vendor/autoload.php');
44

55
use Jobcloud\Kafka\Consumer\KafkaConsumerBuilder;
66
use Jobcloud\Kafka\Exception\KafkaConsumerConsumeException;

Diff for: src/ext-php-rdkafka/php-kafka-lib/producer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require_once('../../../vendor/autoload.php');
3+
require_once('../vendor/autoload.php');
44

55
use Jobcloud\Kafka\Producer\KafkaProducerBuilder;
66
use Jobcloud\Kafka\Message\KafkaProducerMessage;

Diff for: src/ext-php-rdkafka/pure-php/README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
# Running consumer / producer
22

33
## Prerequisites
4-
Be sure to do this first: [Start containers](./../../../README.md#start-containers-for-examples)
4+
Be sure to do this first: [Start containers](./../README.md)
5+
Connect to the php container:
6+
```bash
7+
docker-compose exec php bash
8+
```
59

610
## Producer
711
Will per default produce 10 messages:
812
```bash
9-
cd src/ext-php-rdkafka/pure-php
13+
cd pure-php
1014
php producer.php
1115
```
1216

13-
## High level consumer
17+
## Consumer
1418
Will consume all messages available:
1519
```bash
16-
cd src/ext-php-rdkafka/pure-php
17-
php highLevelConsumer.php
20+
cd pure-php
21+
php consumer.php
1822
```

Diff for: src/ext-php-simple-kafka-client/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Running the examples
2+
1. `docker-compose up -d`
3+
2. `docker-compose exec php composer update`
4+
3. Check the subfolders on how to run the examples

Diff for: src/ext-php-simple-kafka-client/composer.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"require": {
3+
"ext-json": "*",
4+
"flix-tech/avro-serde-php": "^1.4",
5+
"jobcloud/php-console-kafka-schema-registry": "^1.1",
6+
"php-kafka/php-simple-kafka-lib": "dev-main",
7+
"ramsey/uuid": "^4.0"
8+
}
9+
}

0 commit comments

Comments
 (0)