Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AMQP interop based driver. #158

Merged
merged 17 commits into from Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
@@ -1,15 +1,18 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

matrix:
include:
- php: 5.5
env: EXCLUDE_AMQP_INTEROP=true
fast_finish: true


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

before_script:
Expand Down
3 changes: 1 addition & 2 deletions CHANGELOG.md
Expand Up @@ -4,8 +4,7 @@ Yii2 Queue Extension Change Log
2.0.2 under development
-----------------------

- no changes in this release.

- Enh #158: Add Amqp Interop driver (makasim)

## 2.0.1, November 13, 2017

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Expand Up @@ -23,6 +23,7 @@
"require-dev": {
"yiisoft/yii2-redis": "*",
"php-amqplib/php-amqplib": "*",
"enqueue/amqp-lib": "^0.8",
"pda/pheanstalk": "*",
"jeremeamia/superclosure": "*",
"yiisoft/yii2-debug": "*",
Expand All @@ -34,12 +35,14 @@
"yiisoft/yii2-redis": "Need for Redis queue.",
"pda/pheanstalk": "Need for Beanstalk queue.",
"php-amqplib/php-amqplib": "Need for AMQP queue.",
"enqueue/amqp-lib": "Need for AMQP interop queue.",
"ext-gearman": "Need for Gearman queue."
},
"autoload": {
"psr-4": {
"yii\\queue\\": "src",
"yii\\queue\\amqp\\": "src/drivers/amqp",
"yii\\queue\\amqp_interop\\": "src/drivers/amqp_interop",
"yii\\queue\\beanstalk\\": "src/drivers/beanstalk",
"yii\\queue\\db\\": "src/drivers/db",
"yii\\queue\\file\\": "src/drivers/file",
Expand Down
1 change: 1 addition & 0 deletions docs/guide/README.md
Expand Up @@ -18,6 +18,7 @@ Queue Drivers
* [Db](driver-db.md)
* [Redis](driver-redis.md)
* [RabbitMQ](driver-amqp.md)
* [AMQP Interop](driver-amqp-interop.md)
* [Beanstalk](driver-beanstalk.md)
* [Gearman](driver-gearman.md)

Expand Down
67 changes: 67 additions & 0 deletions docs/guide/driver-amqp-interop.md
@@ -0,0 +1,67 @@
AMQP Interop
============

The driver works with RabbitMQ queues.

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.

Advantages:

* It would work with any amqp interop compatible transports, such as

* [enqueue/amqp-ext](https://github.com/php-enqueue/amqp-ext) based on [PHP amqp extension](https://github.com/pdezwart/php-amqp)
* [enqueue/amqp-lib](https://github.com/php-enqueue/amqp-lib) based on [php-amqplib/php-amqplib](https://github.com/php-amqplib/php-amqplib)
* [enqueue/amqp-bunny](https://github.com/php-enqueue/amqp-bunny) based on [bunny](https://github.com/jakubkulhan/bunny)

* Supports priorities
* Supports delays
* Supports ttr
* Supports attempts
* Contains new options like: vhost, connection_timeout, qos_prefetch_count and so on.
* Supports Secure (SSL) AMQP connections.
* An ability to set DSN like: amqp:, amqps: or amqp://user:pass@localhost:1000/vhost

Configuration example:

```php
return [
'bootstrap' => [
'queue', // The component registers own console commands
],
'components' => [
'queue' => [
'class' => \yii\queue\amqp_interop\Queue::class,
'port' => 5672,
'user' => 'guest',
'password' => 'guest',
'queueName' => 'queue',
'driver' => yii\queue\amqp_interop\Queue::ENQUEUE_AMQP_LIB,

// or
'dsn' => 'amqp://guest:guest@localhost:5672/%2F',

// or, same as above
'dsn' => 'amqp:',
],
],
];
```

Console
-------

Console is used to listen and process queued tasks.

```sh
yii queue/listen
```

`listen` command launches a daemon which infinitely queries the queue. If there are new tasks
they're immediately obtained and executed. This method is most efficient when command is properly
daemonized via [supervisor](worker.md#supervisor).

`listen` command has options:

- `--verbose`, `-v`: print executing statuses into console.
- `--isolate`: verbose mode of a job execute. If enabled, execute result of each job will be printed.
- `--color`: highlighting for verbose mode.
2 changes: 2 additions & 0 deletions docs/guide/driver-amqp.md
@@ -1,6 +1,8 @@
RabbitMQ Driver
===============

_**Note:** The driver provides basic support only and misses some features: delaying, priorities and others. Consider using [amqp_interop](driver-amqp-interop.md) driver which supports more features._

The driver works with RabbitMQ queues.

In order for it to work you should add `php-amqplib/php-amqplib` package to your project.
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/retryable.md
Expand Up @@ -88,7 +88,7 @@ priority.
Restrictions
------------

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

Expand All @@ -98,4 +98,5 @@ Full support of retryable implements for [Beanstalk], [DB], [File] and [Redis] d
[Redis]: driver-redis.md
[Sync]: driver-sync.md
[Gearman]: driver-gearman.md
[RabbitMQ]: driver-amqp.md
[RabbitMQ]: driver-amqp.md
[AMQP Interop]: driver-amqp-interop.md
3 changes: 2 additions & 1 deletion docs/guide/worker.md
Expand Up @@ -34,14 +34,15 @@ file.
For more info about Supervisor's configure and usage see [documentation](http://supervisord.org).

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

[File]: driver-file.md
[Db]: driver-db.md
[Redis]: driver-redis.md
[RabbitMQ]: driver-amqp.md
[Beanstalk]: driver-beanstalk.md
[Gearman]: driver-gearman.md
[AMQP Interop]: driver-amqp-interop.md

Systemd
-------
Expand Down
1 change: 0 additions & 1 deletion src/drivers/amqp/Command.php
Expand Up @@ -21,7 +21,6 @@ class Command extends CliCommand
*/
public $queue;


/**
* Listens amqp-queue and runs new jobs.
* It can be used as demon process.
Expand Down
2 changes: 2 additions & 0 deletions src/drivers/amqp/Queue.php
Expand Up @@ -29,6 +29,7 @@ class Queue extends CliQueue
public $queueName = 'queue';
public $exchangeName = 'exchange';
public $vhost = '/';

/**
* @var string command class name
*/
Expand All @@ -44,6 +45,7 @@ class Queue extends CliQueue
protected $channel;



/**
* @inheritdoc
*/
Expand Down
41 changes: 41 additions & 0 deletions src/drivers/amqp_interop/Command.php
@@ -0,0 +1,41 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yii\queue\amqp_interop;

use yii\queue\cli\Command as CliCommand;

/**
* Manages application amqp-queue.
*
* @author Maksym Kotliar <kotlyar.maksim@gmail.com>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since 2.0.2 (or which version is it going to be released it, @zhuravljov ?)

* @since 2.0.2
*/
class Command extends CliCommand
{
/**
* @var Queue
*/
public $queue;

/**
* Listens amqp-queue and runs new jobs.
* It can be used as demon process.
*/
public function actionListen()
{
$this->queue->listen();
}

/**
* Creates all required queues, topics etc
*/
public function actionSetupBroker()
{
$this->queue->setupBroker();
}
}