Skip to content

Commit 5bd05bf

Browse files
Merge pull request #17 from nepster-web/consume
1.0.0-Alpha-2
2 parents ce0bdd1 + 2f66ceb commit 5bd05bf

36 files changed

+1656
-239
lines changed

.docker/Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
FROM php:7.4-fpm-alpine
1+
FROM php:7.4.16-fpm-alpine
22

3+
ARG LOCAL_ENV
34
ARG USER_ID
45
ARG GROUP_ID
56

@@ -19,14 +20,20 @@ RUN apk update && apk add --no-cache \
1920
shadow
2021

2122
RUN docker-php-ext-install \
22-
pdo_sqlite
23+
pdo_sqlite
24+
25+
RUN apk add --no-cache $PHPIZE_DEPS \
26+
&& pecl install xdebug-3.0.3 \
27+
&& docker-php-ext-enable xdebug;
2328

2429
RUN mkdir /db && chown -R ${USER_ID}:${GROUP_ID} /db && /usr/bin/sqlite3 /db/queue.db
2530

26-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
31+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --version=2.0.11 --filename=composer
2732

2833
# Set IDs from our local user
2934
RUN usermod -u ${USER_ID} www-data && groupmod -g ${GROUP_ID} www-data || true
3035
USER "${USER_ID}:${GROUP_ID}"
3136

37+
COPY php.ini /usr/local/etc/php/conf.d/php.ini
38+
3239
WORKDIR /app

.docker/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ USER_ID = $(shell id -u)
44
GROUP_ID=$(shell id -g)
55
APP_DIR="${PWD}/.."
66

7-
app_run := docker exec -t --user="${USER_ID}" $(PROJECT_NAME)
7+
app_run := docker exec -it --user="${USER_ID}" $(PROJECT_NAME)
88

99
.PHONY : help build start stop restart composer php test test-coverage
1010

.docker/php.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[PHP]
2+
xdebug.mode=coverage

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/phpcs.xml
44
/vendor/
55
/.phpunit.result.cache
6-
/.php_cs.cache
6+
/.php_cs.cache
7+
/docs/tmp/

CHANGELOG.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,32 @@ A changelog of all notable changes made to this library.
88

99

1010
1.0.0 under development
11-
-------------------
11+
----------------------
12+
13+
14+
1.0.0-RC under development
15+
----------------------
1216

1317

1418
1.0.0-Beta under development
15-
-------------------
19+
----------------------
20+
21+
22+
1.0.0-Alpha-3 ??.??.2021
23+
------------------------
24+
25+
26+
1.0.0-Alpha-2 17.03.2021
27+
------------------------
28+
- *ENH*: added work with jobs
29+
- *ENH*: added work with processors
30+
- *ENH*: added serializer fo message body
31+
- *ENH*: added [MessageHydrator](./src/MessageHydrator.php) (for change system properties)
32+
- *ENH*: added base [Config](./src/Config.php)
33+
- *ENH*: expanded consumer work algorithms
34+
- *ENH*: increased test coverage
35+
- *ENH*: improved documentation
36+
- *ENH*: updated Dockerfile in example (strict version for: php, composer, xdebug)
1637

1738

1839
1.0.0-Alpha 13.02.2021

README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
> This package is under development. Api classes of this application can be changed.
2+
13
<p align="center">
24
<h1 align="center">PHP Simple Queue</h1>
35
</p>
@@ -50,7 +52,20 @@ or add
5052
:computer: Basic Usage
5153
----------------------
5254

53-
### Send to queue (producing)
55+
Create a database connection:
56+
57+
```php
58+
$connection = \Doctrine\DBAL\DriverManager::getConnection([
59+
'dbname' => 'my_db',
60+
'user' => 'root',
61+
'password' => '*******',
62+
'host' => 'localhost',
63+
'port' => '54320',
64+
'driver' => 'pdo_pgsql',
65+
]);
66+
```
67+
68+
### Send a message to queue (producing)
5469

5570
```php
5671
// $connection - create doctrine connection
@@ -61,20 +76,34 @@ $message = new Message('my_queue', json_decode($data));
6176
$producer->send($message);
6277
```
6378

64-
### Read from queue (consuming)
79+
### Job dispatching (producing)
80+
81+
```php
82+
// $connection - create doctrine connection
83+
84+
$producer = new \Simple\Queue\Producer($connection);
85+
86+
$producer->dispatch(MyJob::class, ['key' => 'value']);
87+
```
88+
89+
### Processing messages from queue (consuming)
6590

6691
```php
6792
// $connection - create doctrine connection
6893

6994
$producer = new \Simple\Queue\Producer($connection);
7095
$consumer = new \Simple\Queue\Consumer($connection, $producer);
7196

72-
while (true) {
73-
if ($message = $consumer->fetchMessage('my_queue')) {
74-
// your message handling logic
75-
$consumer->acknowledge($message);
76-
}
77-
}
97+
// process all messages from queue
98+
$consumer->bind('my_queue', static function(\Simple\Queue\Message $message, \Simple\Queue\Producer $producer): string {
99+
100+
// Your message handling logic
101+
var_dump($message->getBody() . PHP_EOL);
102+
103+
return \Simple\Queue\Consumer::STATUS_ACK;
104+
});
105+
106+
$consumer->consume();
78107
```
79108

80109
For more details see the [example code](./example) and read the [guide](./docs/guide/example.md).
@@ -99,7 +128,6 @@ make comoposer cmd='test'
99128

100129
---------------------------------
101130

102-
103131
## :book: Documentation
104132

105133
See [the official guide](./docs/guide/README.md).

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"ext-json": "*",
2727
"doctrine/dbal": "^3.0",
2828
"laminas/laminas-hydrator": "^4.1",
29-
"ramsey/uuid": "^4.1"
29+
"ramsey/uuid": "^4.1",
30+
"symfony/serializer": "^5.2"
3031
},
3132
"require-dev": {
3233
"roave/security-advisories": "dev-master",

docs/guide/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ It supports queues based on **DB**.
1010

1111
* **[Guide](./README.md)**
1212
* [Install](./install.md)
13-
* [Usage basics](./usage.md)
13+
* [Send message](./send_message.md)
14+
* [Consuming](./consuming.md)
1415
* [Example](./example.md)
1516
* [Cookbook](./cookbook.md)
1617

17-
1818
<br>
1919

2020
[Go back](https://github.com/nepster-web/php-simple-queue)

0 commit comments

Comments
 (0)