Skip to content

Amqp queue #2

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

Merged
merged 2 commits into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"require": {
"php": ">=5.6",
"illuminate/queue": "^5.4",
"queue-interop/queue-interop": "^0.6@dev"
"queue-interop/queue-interop": "^0.6@dev",
"queue-interop/amqp-interop": "^0.6@dev",
"enqueue/amqp-tools": "^0.7@dev"
},
"require-dev": {
"phpunit/phpunit": "~5.5",
Expand All @@ -22,7 +24,7 @@
"enqueue/test": "^0.7@dev"
},
"autoload": {
"psr-4": { "Enqueue\\LaravelQueue\\": "" },
"psr-4": { "Enqueue\\LaravelQueue\\": "src/" },
"exclude-from-classmap": [
"/Tests/"
]
Expand Down
27 changes: 27 additions & 0 deletions src/AmqpConnector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Enqueue\LaravelQueue;

use Enqueue\AmqpTools\DelayStrategyAware;
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
use Interop\Amqp\AmqpContext;

class AmqpConnector extends Connector
{
public function connect(array $config)
{
$queue = parent::connect($config);

/** @var AmqpContext $amqpContext */
$amqpContext = $queue->getPsrContext();
if (false == $amqpContext instanceof AmqpContext) {
throw new \LogicException(sprintf('The context must be instance of "%s" but got "%s"', AmqpContext::class, get_class($queue->getPsrContext())));
}

if ($amqpContext instanceof DelayStrategyAware) {
$amqpContext->setDelayStrategy(new RabbitMqDlxDelayStrategy());
}

return $queue;
}
}
62 changes: 62 additions & 0 deletions src/AmqpQueue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Enqueue\LaravelQueue;

use Interop\Amqp\AmqpContext;

/**
* @method AmqpContext getPsrContext()
*/
class AmqpQueue extends Queue
{
/**
* {@inheritdoc}
*
* @param AmqpContext $psrContext
*/
public function __construct(AmqpContext $psrContext, $queueName, $timeToRun)
{
parent::__construct($psrContext, $queueName, $timeToRun);
}

/**
* {@inheritdoc}
*/
public function pushRaw($payload, $queue = null, array $options = [])
{
$this->declareQueue($queue);

parent::pushRaw($payload, $queue, $options);
}

/**
* {@inheritdoc}
*/
public function later($delay, $job, $data = '', $queue = null)
{
$this->declareQueue($queue);

return parent::later($delay, $job, $data, $queue);
}

/**
* {@inheritdoc}
*/
public function pop($queue = null)
{
$this->declareQueue($queue);

return parent::pop($queue);
}

/**
* @param string|null $queue
*/
protected function declareQueue($queue = null)
{
$psrQueue = $this->getPsrContext()->createQueue($this->getQueue($queue));
$psrQueue->addFlag(\Interop\Amqp\AmqpQueue::FLAG_DURABLE);

$this->getPsrContext()->declareQueue($psrQueue);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions EnqueueServiceProvider.php → src/EnqueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,9 @@ private function bootInteropQueueDriver()
$manager->addConnector('interop', function () {
return new Connector();
});

$manager->addConnector('amqp_interop', function () {
return new AmqpConnector();
});
}
}
File renamed without changes.
3 changes: 2 additions & 1 deletion Queue.php → src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class Queue extends BaseQueue implements QueueContract
* @var int
*/
protected $timeToRun;

/**
* @var PsrContext
*/
private $psrContext;
protected $psrContext;

/**
* @param PsrContext $psrContext
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.