Skip to content

Add persistent functionality #7

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 4 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ It also supports extended AMQP features such as queue declaration and message de

The package allows you to use queue interop transport the [laravel way](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/laravel/queues.md) as well as integrates the [enqueue simple client](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/laravel/quick_tour.md#enqueue-simple-client).

To make message [persistent](https://www.rabbitmq.com/persistence-conf.html) add to Laravel Job class field `public $persistent = true;`
## Resources

* [Documentation](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md)
Expand Down
16 changes: 12 additions & 4 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ public function push($job, $data = '', $queue = null)
*/
public function pushRaw($payload, $queue = null, array $options = [])
{
$message = $this->psrContext->createMessage($payload);

if ($message instanceof \Interop\Amqp\Impl\AmqpMessage) {
Copy link
Member

Choose a reason for hiding this comment

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

could you import namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For interface \Interop\Amqp\AmqpMessage or implementation Interop\Amqp\AmqpMessage?
We can't use both or I could use an alias. Which you prefer?

Copy link
Member

Choose a reason for hiding this comment

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

use Interop\Amqp\AmqpMessage;

if ($message instanceof AmqpMessage) {

$message->setDeliveryMode(\Interop\Amqp\AmqpMessage::DELIVERY_MODE_PERSISTENT);
}

return $this->psrContext->createProducer()->send(
$this->getQueue($queue),
$this->psrContext->createMessage($payload)
$message
);
}

Expand All @@ -69,11 +75,13 @@ public function later($delay, $job, $data = '', $queue = null)
{
$message = $this->psrContext->createMessage($this->createPayload($job, $data));

if ($message instanceof \Interop\Amqp\Impl\AmqpMessage) {
$message->setDeliveryMode(\Interop\Amqp\AmqpMessage::DELIVERY_MODE_PERSISTENT);
}

return $this->psrContext->createProducer()
->setDeliveryDelay($this->secondsUntil($delay) * 1000)

->send($this->getQueue($queue), $message)
;
->send($this->getQueue($queue), $message);
}

/**
Expand Down