Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Messenger] [Amqp] Allow sendable AmqpStamp for failure routing #59161

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

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
Loading
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Bridge\Amqp\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceivedStamp;
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpSender;
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpStamp;
use Symfony\Component\Messenger\Bridge\Amqp\Transport\Connection;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Stamp\RedeliveryStamp;
use Symfony\Component\Messenger\Stamp\SentToFailureTransportStamp;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;

/**
Expand Down Expand Up @@ -55,6 +58,48 @@ public function testItSendsTheEncodedMessageUsingARoutingKey()
$sender->send($envelope);
}

public function testItSendsTheEncodedMessageUsingARoutingKeyOnRetry()
{
$envelope = (new Envelope(new DummyMessage('Oy')))
->with($previousStamp = new AmqpStamp('rk'))
->with(new AmqpReceivedStamp($amqpEnvelope = new \AMQPEnvelope(), 'queueName'))
->with(new RedeliveryStamp(1))
;
$encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];

$serializer = $this->createMock(SerializerInterface::class);
$serializer->method('encode')->with($envelope)->willReturn($encoded);

$connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('publish')->with(
$encoded['body'],
$encoded['headers'],
0,
AmqpStamp::createFromAmqpEnvelope($amqpEnvelope, $previousStamp, 'queueName')
);

$sender = new AmqpSender($connection, $serializer);
$sender->send($envelope);
}

public function testItSendsTheEncodedMessageUsingARoutingKeyOnFailure()
{
$envelope = (new Envelope(new DummyMessage('Oy')))
->with($stamp = new AmqpStamp('rk'))
->with(new SentToFailureTransportStamp('originalReceiverName'))
;
$encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];

$serializer = $this->createMock(SerializerInterface::class);
$serializer->method('encode')->with($envelope)->willReturn($encoded);

$connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('publish')->with($encoded['body'], $encoded['headers'], 0, $stamp);

$sender = new AmqpSender($connection, $serializer);
$sender->send($envelope);
}

public function testItSendsTheEncodedMessageWithoutHeaders()
{
$envelope = new Envelope(new DummyMessage('Oy'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Stamp\DelayStamp;
use Symfony\Component\Messenger\Stamp\RedeliveryStamp;
use Symfony\Component\Messenger\Stamp\SentToFailureTransportStamp;
use Symfony\Component\Messenger\Transport\Sender\SenderInterface;
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
Expand Down Expand Up @@ -56,10 +57,14 @@ public function send(Envelope $envelope): Envelope

$amqpReceivedStamp = $envelope->last(AmqpReceivedStamp::class);
if ($amqpReceivedStamp instanceof AmqpReceivedStamp) {
$isRetry = null === $envelope->last(SentToFailureTransportStamp::class)
&& null !== $envelope->last(RedeliveryStamp::class)
;

$amqpStamp = AmqpStamp::createFromAmqpEnvelope(
$amqpReceivedStamp->getAmqpEnvelope(),
$amqpStamp,
$envelope->last(RedeliveryStamp::class) ? $amqpReceivedStamp->getQueueName() : null
$isRetry ? $amqpReceivedStamp->getQueueName() : null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

namespace Symfony\Component\Messenger\Bridge\Amqp\Transport;

use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;
use Symfony\Component\Messenger\Stamp\StampInterface;

/**
* @author Guillaume Gammelin <ggammelin@gmail.com>
* @author Samuel Roze <samuel.roze@gmail.com>
*/
final class AmqpStamp implements NonSendableStampInterface
final class AmqpStamp implements StampInterface
{
private bool $isRetryAttempt = false;

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.