8000 Add Amqp interop based driver. · yiisoft/yii2-queue@44570a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 44570a3

Browse files
committed
Add Amqp interop based driver.
1 parent b158787 commit 44570a3

File tree

15 files changed

+562
-5
lines changed

15 files changed

+562
-5
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
language: php
22

33
php:
4-
- 5.5
54
- 5.6
65
- 7.0
76
- 7.1
87
- 7.2
98

109
matrix:
10+
include:
11+
- php: 5.5
12+
env: EXCLUDE_AMQP_INTEROP=true
1113
fast_finish: true
1214

15+
1316
services:
1417
- mysql
1518
- postgresql
@@ -31,6 +34,7 @@ before_install:
3134
install:
3235
- travis_retry composer self-update && composer --version
3336
- export PATH="$HOME/.composer/vendor/bin:$PATH"
37+
- if [ "$EXCLUDE_AMQP_INTEROP" = true ]; then travis_retry composer remove "enqueue/amqp-lib" "enqueue/amqp-tools" --dev --no-interaction --no-update; fi
3438
- travis_retry composer install --prefer-dist --no-interaction
3539

3640
before_script:

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"require-dev": {
2424
"yiisoft/yii2-redis": "*",
2525
"php-amqplib/php-amqplib": "*",
26+
"enqueue/amqp-lib": "^0.8",
2627
"pda/pheanstalk": "*",
2728
"jeremeamia/superclosure": "*",
2829
"yiisoft/yii2-debug": "*",
@@ -34,6 +35,7 @@
3435
"yiisoft/yii2-redis": "Need for Redis queue.",
3536
"pda/pheanstalk": "Need for Beanstalk queue.",
3637
"php-amqplib/php-amqplib": "Need for AMQP queue.",
38+
"enqueue/amqp-lib": "Need for AMQP interop queue.",
3739
"ext-gearman": "Need for Gearman queue."
3840
},
3941
"autoload": {

docs/guide/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Queue Drivers
1818
* [Db](driver-db.md)
1919
* [Redis](driver-redis.md)
2020
* [RabbitMQ](driver-amqp.md)
21+
* [AMQP Interop)](driver-amqp-interop.md)
2122
* [Beanstalk](driver-beanstalk.md)
2223
* [Gearman](driver-gearman.md)
2324

docs/guide/driver-amqp-interop.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
AMQP Interop
2+
============
3+
4+
The driver works with RabbitMQ queues.
5+
6+
In order for it to work you should add any [amqp interop](https://github.com/queue-interop/queue-interop#amqp-interop) compatible transport to your project, for example `enqueue/amqp-lib` package.
7+
8+
Configuration example:
9+
10+
```php
11+
return [
12+
'bootstrap' => [
13+
'queue', // The component registers own console commands
14+
],
15+
'components' => [
16+
'queue' => [
17+
'class' => \yii\queue\amqp_interop\Queue::class,
18+
'port' => 5672,
19+
'user' => 'guest',
20+
'password' => 'guest',
21+
'queueName' => 'queue',
22+
'driver' => 'lib',
23+
24+
// or
25+
'dsn' => 'amqp://guest:guest@localhost:5672/%2F',
26+
27+
// or (same as above
28+
'dsn' => 'amqp:',
29+
],
30+
],
31+
];
32+
```
33+
34+
Console
35+
-------
36+
37+
Console is used to listen and process queued tasks.
38+
39+
```sh
40+
yii queue/listen
41+
```
42+
43+
`listen` command launches a daemon which infinitely queries the queue. If there are new tasks
44+
they're immediately obtained and executed. This method is most efficient when command is properly
45+
daemonized via [supervisor](worker.md#supervisor).
46+
47+
`listen` command has options:
48+
49+
- `--verbose`, `-v`: print executing statuses into console.
50+
- `--isolate`: verbose mode of a job execute. If enabled, execute result of each job will be printed.
51+
- `--color`: highlighting for verbose mode.

docs/guide/driver-amqp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
RabbitMQ Driver
22
===============
33

4+
_**Note:** The driver hsa been deprecated since 2.1 will be removed in 3.0. Consider using [amqp_interop](driver-amqp-interop.md) driver instead._
5+
46
The driver works with RabbitMQ queues.
57

68
In order for it to work you should add `php-amqplib/php-amqplib` package to your project.

docs/guide/retryable.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ priority.
8888
Restrictions
8989
------------
9090

91-
Full support of retryable implements for [Beanstalk], [DB], [File] and [Redis] drivers.
91+
Full support of retryable implements for [Beanstalk], [DB], [File], [AMQP Interop] and [Redis] drivers.
9292
[Sync] driver will not retry failed jobs. [Gearman] driver doesn't support of retryable.
9393
[RabbitMQ] has only its basic retryable support, in which an attempt number can not be got.
9494

@@ -98,4 +98,5 @@ Full support of retryable implements for [Beanstalk], [DB], [File] and [Redis] d
9898
[Redis]: driver-redis.md
9999
[Sync]: driver-sync.md
100100
[Gearman]: driver-gearman.md
101-
[RabbitMQ]: driver-amqp.md
101+
[RabbitMQ]: driver-amqp.md
102+
[AMQP Interop]: driver-amqp-interop.md

docs/guide/worker.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ file.
3434
For more info about Supervisor's configure and usage see [documentation](http://supervisord.org).
3535

3636
Worker starting in daemon mode with `queue/listen` command supports [File], [Db], [Redis],
37-
[RabbitMQ], [Beanstalk], [Gearman] drivers. For additional options see driver guide.
37+
[RabbitMQ], [AMQP Interop], [Beanstalk], [Gearman] drivers. For additional options see driver guide.
3838

3939
[File]: driver-file.md
4040
[Db]: driver-db.md
4141
[Redis]: driver-redis.md
4242
[RabbitMQ]: driver-amqp.md
4343
[Beanstalk]: driver-beanstalk.md
4444
[Gearman]: driver-gearman.md
45+
[AMQP Interop]: driver-amqp-interop.md
4546

4647
Systemd
4748
-------

src/drivers/amqp/Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use yii\queue\cli\Command as CliCommand;
1111

1212
/**
13+
* @deprecated since 2.1 will be removed in 3.0. Consider using amqp_interop driver instead
14+
*
1315
* Manages application amqp-queue.
1416
*
1517
* @author Roman Zhuravlev <zhuravljov@gmail.com>
@@ -21,7 +23,6 @@ class Command extends CliCommand
2123
*/
2224
public $queue;
2325

24-
2526
/**
2627
* Listens amqp-queue and runs new jobs.
2728
* It can be used as demon process.

src/drivers/amqp/Queue.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use yii\queue\cli\Queue as CliQueue;
1717

1818
/**
19+
* @deprecated since 2.1 will be removed in 3.0. Consider using amqp_interop driver instead
20+
*
1921
* Amqp Queue
2022
*
2123
* @author Roman Zhuravlev <zhuravljov@gmail.com>
@@ -29,6 +31,7 @@ class Queue extends CliQueue
2931
public $queueName = 'queue';
3032
public $exchangeName = 'exchange';
3133
public $vhost = '/';
34+
3235
/**
3336
* @var string command class name
3437
*/
@@ -44,6 +47,7 @@ class Queue extends CliQueue
4447
protected $channel;
4548

4649

50+
4751
/**
4852
* @inheritdoc
4953
*/

src/drivers/amqp_interop/Command.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* @link http://www.yiiframework.com/
4+
* @copyright Copyright (c) 2008 Yii Software LLC
5+
* @license http://www.yiiframework.com/license/
6+
*/
7+
8+
namespace yii\queue\amqp_interop;
9+
10+
use yii\queue\cli\Command as CliCommand;
11+
12+
/**
13+
* Manages application amqp-queue.
14+
*
15+
* @author Roman Zhuravlev <zhuravljov@gmail.com>
16+
*/
17+
class Command extends CliCommand
18+
{
19+
/**
20+
* @var Queue
21+
*/
22+
public $queue;
23+
24+
/**
25+
* Listens amqp-queue and runs new jobs.
26+
* It can be used as demon process.
27+
*/
28+
public function actionListen()
29+
{
30+
$this->queue->listen();
31+
}
32+
33+
/**
34+
* Creates all required queues, topics etc
35+
*/
36+
public function actionSetupBroker()
37+
{
38+
$this->queue->setupBroker();
39+
}
40+
}

0 commit comments

Comments
 (0)
0