Skip to content

Commit aca0fc4

Browse files
authored
Merge pull request #134 from php-enqueue/kafka
RdKafka Transport
2 parents 18e15bb + d26a6f2 commit aca0fc4

34 files changed

+1749
-15
lines changed

Diff for: .travis.yml

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
sudo: required
2+
13
git:
24
depth: 10
35

@@ -6,37 +8,27 @@ language: php
68
matrix:
79
include:
810
- php: 5.6
9-
sudo: false
1011
env: SYMFONY_VERSION=2.8.* UNIT_TESTS=true
1112
- php: 7.1
12-
sudo: false
1313
env: SYMFONY_VERSION=3.0.* PHPSTAN=true
1414
- php: 7.1
15-
sudo: false
1615
env: SYMFONY_VERSION=3.0.* PHP_CS_FIXER=true
1716
- php: 7.0
18-
sudo: false
1917
env: SYMFONY_VERSION=2.8.* UNIT_TESTS=true
2018
- php: 5.6
21-
sudo: false
2219
env: SYMFONY_VERSION=3.0.* UNIT_TESTS=true SYMFONY_DEPRECATIONS_HELPER=weak
2320
- php: 7.0
24-
sudo: false
2521
env: SYMFONY_VERSION=3.0.* UNIT_TESTS=true SYMFONY_DEPRECATIONS_HELPER=weak
2622
- php: 7.1
27-
sudo: required
2823
services: docker
2924
env: SYMFONY_VERSION=2.8.* FUNCTIONAL_TESTS=true
3025
- php: 7.1
31-
sudo: required
3226
services: docker
3327
env: SYMFONY_VERSION=3.0.* FUNCTIONAL_TESTS=true
3428
- php: 7.1
35-
sudo: required
3629
services: docker
3730
env: SYMFONY_VERSION=3.2.* FUNCTIONAL_TESTS=true
3831
- php: 7.1
39-
sudo: required
4032
services: docker
4133
env: SYMFONY_VERSION=3.3.* FUNCTIONAL_TESTS=true
4234

@@ -54,8 +46,7 @@ install:
5446
- if [ "$FUNCTIONAL_TESTS" = true ]; then bin/dev -b; fi
5547

5648
script:
57-
# misssing pkg/amqp-ext pkg/job-queue pkg/redis
58-
- if [ "$PHPSTAN" = true ]; then php -d memory_limit=512M bin/phpstan analyse -l 1 -c phpstan.neon pkg/amqp-ext pkg/async-event-dispatcher pkg/dbal pkg/enqueue pkg/enqueue-bundle pkg/fs pkg/gearman pkg/job-queue pkg/null pkg/pheanstalk pkg/redis pkg/simple-client pkg/sqs pkg/stomp pkg/test; fi
49+
- if [ "$PHPSTAN" = true ]; then php -d memory_limit=512M bin/phpstan analyse -l 1 -c phpstan.neon pkg/amqp-ext pkg/async-event-dispatcher pkg/dbal pkg/enqueue pkg/enqueue-bundle pkg/fs pkg/gearman pkg/job-queue pkg/null pkg/pheanstalk pkg/redis pkg/simple-client pkg/sqs pkg/stomp pkg/test pkg/rdkafka; fi
5950
- if [ "$PHP_CS_FIXER" = true ]; then IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}")); unset IFS; fi
6051
- if [ "$PHP_CS_FIXER" = true ]; then ./bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}"; fi
6152
- if [ "$UNIT_TESTS" = true ]; then bin/phpunit --exclude-group=functional; fi

Diff for: README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ Features:
99

1010
* [Feature rich](docs/quick_tour.md).
1111
* Implements [JMS](https://docs.oracle.com/javaee/7/api/javax/jms/package-summary.html) like transports based on a[queue-interop](https://github.com/queue-interop/queue-interop) interfaces.
12-
* Supported transports [AMQP](docs/transport/amqp.md) (RabbitMQ, ActiveMQ), [Beanstalk](docs/transport/pheanstalk.md), [STOMP](docs/transport/stomp.md), [Amazon SQS](docs/transport/sqs.md), [Redis](docs/transport/redis.md), [Gearman](docs/transport/gearman.md), [Doctrine DBAL](docs/transport/dbal.md), [Filesystem](docs/transport/filesystem.md), [Null](docs/transport/null.md).
12+
* Supported transports
13+
* [AMQP](docs/transport/amqp.md) (RabbitMQ, ActiveMQ)
14+
* [Beanstalk](docs/transport/pheanstalk.md)
15+
* [STOMP](docs/transport/stomp.md)
16+
* [Amazon SQS](docs/transport/sqs.md)
17+
* [Kafka](docs/transport/kafka.md)
18+
* [Redis](docs/transport/redis.md)
19+
* [Gearman](docs/transport/gearman.md)
20+
* [Doctrine DBAL](docs/transport/dbal.md)
21+
* [Filesystem](docs/transport/filesystem.md)
22+
* [Null](docs/transport/null.md).
1323
* [Symfony bundle](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/bundle/quick_tour.md)
1424
* [Magento1 extension](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/magento/quick_tour.md)
1525
* [Message bus](http://www.enterpriseintegrationpatterns.com/patterns/messaging/MessageBus.html) support.

Diff for: bin/test

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ waitForService mysql 3306 50
2525
waitForService redis 6379 50
2626
waitForService beanstalkd 11300
2727
waitForService gearmand 4730
28+
waitForService kafka 9092
2829

2930
php pkg/job-queue/Tests/Functional/app/console doctrine:database:create
3031
php pkg/job-queue/Tests/Functional/app/console doctrine:schema:update --force

Diff for: composer.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"enqueue/sqs": "*@dev",
1515
"enqueue/pheanstalk": "*@dev",
1616
"enqueue/gearman": "*@dev",
17+
"enqueue/rdkafka": "*@dev",
18+
"kwn/php-rdkafka-stubs": "^1.0.2",
1719
"enqueue/enqueue-bundle": "*@dev",
1820
"enqueue/job-queue": "*@dev",
1921
"enqueue/simple-client": "*@dev",
@@ -35,7 +37,16 @@
3537
"phpstan/phpstan": "^0.7.0"
3638
},
3739
"autoload": {
38-
"files": ["pkg/enqueue/functions_include.php"]
40+
"files": [
41+
"pkg/enqueue/functions_include.php",
42+
"pkg/rdkafka/Tests/bootstrap.php"
43+
],
44+
"psr-0": {
45+
"RdKafka": "vendor/kwn/php-rdkafka-stubs/stubs"
46+
},
47+
"psr-4": {
48+
"RdKafka\\": "vendor/kwn/php-rdkafka-stubs/stubs/RdKafka"
49+
}
3950
},
4051
"config": {
4152
"bin-dir": "bin"
@@ -93,6 +104,10 @@
93104
"type": "path",
94105
"url": "pkg/gearman"
95106
},
107+
{
108+
"type": "path",
109+
"url": "pkg/rdkafka"
110+
},
96111
{
97112
"type": "path",
98113
"url": "pkg/simple-client"

Diff for: docker-compose.yml

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ services:
1010
- redis
1111
- beanstalkd
1212
- gearmand
13+
- kafka
14+
- zookeeper
1315
volumes:
1416
- './:/mqdev'
1517
environment:
@@ -36,6 +38,8 @@ services:
3638
- BEANSTALKD_PORT=11300
3739
- BEANSTALKD_DSN=beanstalk://beanstalkd:11300
3840
- GEARMAN_DSN=gearman://gearmand:4730
41+
- RDKAFKA_HOST=kafka
42+
- RDKAFKA_PORT=9092
3943

4044
rabbitmq:
4145
image: enqueue/rabbitmq:latest
@@ -71,6 +75,20 @@ services:
7175
volumes:
7276
- ./:/mqdev
7377

78+
zookeeper:
79+
image: 'wurstmeister/zookeeper'
80+
ports:
81+
- '2181:2181'
82+
83+
kafka:
84+
image: 'wurstmeister/kafka:0.10.2.1'
85+
ports:
86+
- '9092:9092'
87+
environment:
88+
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
89+
volumes:
90+
- '/var/run/docker.sock:/var/run/docker.sock'
91+
7492
volumes:
7593
mysql-data:
7694
driver: local

Diff for: docker/Dockerfile

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ FROM formapro/nginx-php-fpm:latest-all-exts
33
## libs
44
RUN set -x && \
55
apt-get update && \
6-
apt-get install -y --no-install-recommends wget curl openssl ca-certificates nano netcat php-redis
6+
apt-get install -y wget curl openssl ca-certificates nano netcat php-dev php-redis git python
77

88
## confis
99

1010
# RUN rm -f /etc/php/7.0/cli/conf.d/*xdebug.ini
1111

12+
## librdkafka
13+
RUN git clone https://github.com/edenhill/librdkafka.git /root/librdkafka
14+
RUN cd /root/librdkafka && git checkout v0.11.0-RC2 && ./configure && make && make install
15+
RUN pecl install rdkafka
16+
RUN echo "extension=rdkafka.so" > /etc/php/7.1/cli/conf.d/10-rdkafka.ini
17+
RUN echo "extension=rdkafka.so" > /etc/php/7.1/fpm/conf.d/10-rdkafka.ini
18+
1219
COPY ./php/cli.ini /etc/php/7.1/cli/conf.d/1-dev_cli.ini
1320
COPY ./bin/dev_entrypoiny.sh /usr/local/bin/entrypoint.sh
1421
RUN chmod u+x /usr/local/bin/entrypoint.sh

Diff for: docs/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- [Amqp (RabbitMQ, ActiveMQ)](transport/amqp.md)
66
- [Amazon SQS](transport/sqs.md)
77
- [Beanstalk (Pheanstalk)](transport/pheanstalk.md)
8+
- [Gearman](transport/gearman.md)
9+
- [Kafka](transport/kafka.md)
810
- [Stomp](transport/stomp.md)
911
- [Redis](transport/redis.md)
1012
- [Doctrine DBAL](transport/dbal.md)

Diff for: docs/transport/kafka.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Kafka transport
2+
3+
The transport uses [Kafka](https://kafka.apache.org/) streaming platform as a MQ broker.
4+
5+
* [Installation](#installation)
6+
* [Create context](#create-context)
7+
* [Send message to topic](#send-message-to-topic)
8+
* [Send message to queue](#send-message-to-queue)
9+
* [Consume message](#consume-message)
10+
11+
## Installation
12+
13+
```bash
14+
$ composer require enqueue/rdkafka
15+
```
16+
17+
## Create context
18+
19+
```php
20+
<?php
21+
use Enqueue\RdKafka\RdKafkaConnectionFactory;
22+
23+
// connects to localhost:9092
24+
$connectionFactory = new RdKafkaConnectionFactory();
25+
26+
// same as above
27+
$connectionFactory = new RdKafkaConnectionFactory('rdkafka://');
28+
29+
// same as above
30+
$connectionFactory = new RdKafkaConnectionFactory([]);
31+
32+
// connect to Kafka broker at example.com:1000 plus custom options
33+
$connectionFactory = new RdKafkaConnectionFactory([
34+
'global' => [
35+
'group.id' => uniqid('', true),
36+
'metadata.broker.list' => 'example.com:1000',
37+
'enable.auto.commit' => 'false',
38+
],
39+
'topic' => [
40+
'auto.offset.reset' => 'beginning',
41+
],
42+
]);
43+
44+
$psrContext = $connectionFactory->createContext();
45+
```
46+
47+
## Send message to topic
48+
49+
```php
50+
<?php
51+
/** @var \Enqueue\RdKafka\RdKafkaContext $psrContext */
52+
53+
$message = $psrContext->createMessage('Hello world!');
54+
55+
$fooTopic = $psrContext->createTopic('foo');
56+
57+
$psrContext->createProducer()->send($fooTopic, $message);
58+
```
59+
60+
## Send message to queue
61+
62+
```php
63+
<?php
64+
/** @var \Enqueue\RdKafka\RdKafkaContext $psrContext */
65+
66+
$message = $psrContext->createMessage('Hello world!');
67+
68+
$fooQueue = $psrContext->createQueue('foo');
69+
70+
$psrContext->createProducer()->send($fooQueue, $message);
71+
```
72+
73+
## Consume message:
74+
75+
```php
76+
<?php
77+
/** @var \Enqueue\RdKafka\RdKafkaContext $psrContext */
78+
79+
$fooQueue = $psrContext->createQueue('foo');
80+
81+
$consumer = $psrContext->createConsumer($fooQueue);
82+
83+
$message = $consumer->receive();
84+
85+
// process a message
86+
87+
$consumer->acknowledge($message);
88+
// $consumer->reject($message);
89+
```
90+
91+
[back to index](index.md)

Diff for: phpunit.xml.dist

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
<directory>pkg/gearman/Tests</directory>
5454
</testsuite>
5555

56+
<testsuite name="rdkafka transport">
57+
<directory>pkg/rdkafka/Tests</directory>
58+
</testsuite>
59+
5660
<testsuite name="enqueue-bundle">
5761
<directory>pkg/enqueue-bundle/Tests</directory>
5862
</testsuite>

Diff for: pkg/rdkafka/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*~
2+
/composer.lock
3+
/composer.phar
4+
/phpunit.xml
5+
/vendor/
6+
/.idea/

Diff for: pkg/rdkafka/.travis.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
sudo: false
2+
3+
git:
4+
depth: 1
5+
6+
language: php
7+
8+
php:
9+
- '5.6'
10+
- '7.0'
11+
12+
cache:
13+
directories:
14+
- $HOME/.composer/cache
15+
16+
install:
17+
- composer self-update
18+
- composer install --prefer-source --ignore-platform-reqs
19+
20+
script:
21+
- vendor/bin/phpunit --exclude-group=functional

Diff for: pkg/rdkafka/LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2016 Kotliar Maksym
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is furnished
9+
to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.

Diff for: pkg/rdkafka/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# RdKafka Transport
2+
3+
[![Gitter](https://badges.gitter.im/php-enqueue/Lobby.svg)](https://gitter.im/php-enqueue/Lobby)
4+
[![Build Status](https://travis-ci.org/php-enqueue/rdkafka.png?branch=master)](https://travis-ci.org/php-enqueue/rdkafka)
5+
[![Total Downloads](https://poser.pugx.org/enqueue/rdkafka/d/total.png)](https://packagist.org/packages/enqueue/rdkafka)
6+
[![Latest Stable Version](https://poser.pugx.org/enqueue/rdkafka/version.png)](https://packagist.org/packages/enqueue/rdkafka)
7+
8+
This is an implementation of PSR specification. It allows you to send and consume message via Kafka protocol.
9+
10+
## Resources
11+
12+
* [Documentation](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md)
13+
* [Questions](https://gitter.im/php-enqueue/Lobby)
14+
* [Issue Tracker](https://github.com/php-enqueue/enqueue-dev/issues)
15+
16+
## Developed by Forma-Pro
17+
18+
Forma-Pro is a full stack development company which interests also spread to open source development.
19+
Being a team of strong professionals we have an aim an ability to help community by developing cutting edge solutions in the areas of e-commerce, docker & microservice oriented architecture where we have accumulated a huge many-years experience.
20+
Our main specialization is Symfony framework based solution, but we are always looking to the technologies that allow us to do our job the best way. We are committed to creating solutions that revolutionize the way how things are developed in aspects of architecture & scalability.
21+
22+
If you have any questions and inquires about our open source development, this product particularly or any other matter feel free to contact at opensource@forma-pro.com
23+
24+
## License
25+
26+
It is released under the [MIT License](LICENSE).

0 commit comments

Comments
 (0)