8000 [Messenger] fix publishing headers set on AmqpStamp by Tobion · Pull Request #32413 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] fix publishing headers set on AmqpStamp #32413

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 1 commit into from
Jul 8, 2019
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
[Messenger] fix publishing headers set on AmqpStamp
  • Loading branch information
Tobion committed Jul 6, 2019
commit 50b3ec4dc507c6448411f14f8051e449470016ad
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,21 @@ public function testObfuscatePasswordInDsn()
$connection->channel();
}

public function testAmqpStampHeadersAreUsed()
{
$factory = new TestAmqpFactory(
$this->createMock(\AMQPConnection::class),
$this->createMock(\AMQPChannel::class),
$this->createMock(\AMQPQueue::class),
$amqpExchange = $this->createMock(\AMQPExchange::class)
);

$amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => ['Foo' => 'X', 'Bar' => 'Y']]);

$connection = Connection::fromDsn('amqp://localhost', [], $factory);
$connection->publish('body', ['Foo' => 'X'], 0, new AmqpStamp(null, AMQP_NOPARAM, ['headers' => ['Bar' => 'Y']]));
}

public function testItCanPublishWithTheDefaultRoutingKey()
{
$factory = new TestAmqpFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace Symfony\Component\Messenger\Transport\AmqpExt;

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

/**
* @author Guillaume Gammelin <ggammelin@gmail.com>
* @author Samuel Roze <samuel.roze@gmail.com>
*
* @experimental in 4.3
*/
final class AmqpStamp implements StampInterface
final class AmqpStamp implements NonSendableStampInterface
{
private $routingKey;
private $flags;
Expand Down
15 changes: 7 additions & 8 deletions src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ public function publish(string $body, array $headers = [], int $delay = 0, AmqpS
$this->exchange(),
$body,
$this->getRoutingKeyForMessage($amqpStamp),
[
'headers' => $headers,
],
$headers,
$amqpStamp
);
}
Expand Down Expand Up @@ -223,20 +221,21 @@ private function publishWithDelay(string $body, array $headers, int $delay, Amqp
$this->getDelayExchange(),
$body,
$this->getRoutingKeyForDelay($delay, $routingKey),
[
'headers' => $headers,
],
$headers,
$amqpStamp
);
}

private function publishOnExchange(\AMQPExchange $exchange, string $body, string $routingKey = null, array $attributes = [], AmqpStamp $amqpStamp = null)
private function publishOnExchange(\AMQPExchange $exchange, string $body, string $routingKey = null, array $headers = [], AmqpStamp $amqpStamp = null)
{
$attributes = $amqpStamp ? $amqpStamp->getAttributes() : [];
$attributes['headers'] = array_merge($headers, $attributes['headers'] ?? []);

$exchange->publish(
$body,
$routingKey,
$amqpStamp ? $amqpStamp->getFlags() : AMQP_NOPARAM,
array_merge($amqpStamp ? $amqpStamp->getAttributes() : [], $attributes)
$attributes
);
}

Expand Down
0