-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger][AMQP] Use delivery_mode=2 by default #34956
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
Conversation
lyrixx
commented
Dec 12, 2019
Q | A |
---|---|
Branch? | master |
Bug fix? | no |
New feature? | no |
Deprecations? | no |
Tickets | Fix #34685 |
License | MIT |
Doc PR |
I have tested it: <?php
use Symfony\Component\Messenger\Transport\AmqpExt\AmqpStamp;
use Symfony\Component\Messenger\Transport\AmqpExt\Connection;
require __DIR__.'/vendor/autoload.php';
$connection = Connection::fromDsn('amqp://rabbitmq-3.lxd?exchange[name]=test');
$connection->publish('body', [], 0, new AmqpStamp('test')); I have created an exchange (fanout) and a queue by hand. This is not related, but I notice something strange: The component created the a queue OK, I tried $connection = Connection::fromDsn('amqp://rabbitmq-3.lxd?exchange[name]=test&queues[test]=&queues[test2]=');
$connection->publish('body', [], 0, new AmqpStamp('test')); And it does what I want 👍 So now I have another question: If I want to publish to 2 different exchanges, I have to create 2 connection? |
Shouldn't this PR be considered as a bug fix? If not, that means that Symfony 4.4 & 5.0 will provide an AMQP connection that is not safe to use by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As bug fix on 4.4/4.3 as it fits.
a1cb2ab
to
be2eb6f
Compare
I updated the PR to target 4.3 |
Thank you @lyrixx. |
This PR was merged into the 4.3 branch. Discussion ---------- [Messenger][AMQP] Use delivery_mode=2 by default | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #34685 | License | MIT | Doc PR | Commits ------- be2eb6f [Messenger][AMQP] Use delivery_mode=2 by default
About the “messages” queue being created, you could create a separate issue for that. There is a queues config option and I think you could set it to an empty array to avoid this (but I could be wrong). In general, there are many different ways for using Amqp - and so we need to make it work as smoothly as possible for as many cases as we can. |
Seems fine to do this by default as many people don't know the default settings of AMQP it seems. But it will make the AMQP way slower. I used a transport decorator for this so far when I needed it. /**
* Decorates a transport and makes all messages getting sent persistent.
*/
class PersistentMessagesTransportDecorator implements TransportInterface, SetupableTransportInterface
{
private const DELIVERY_MODE_PERSISTENT = 2;
/**
* @var TransportInterface
*/
private $decoratedTransport;
public function __construct(TransportInterface $decoratedTransport)
{
$this->decoratedTransport = $decoratedTransport;
}
public function setup(): void
{
if ($this->decoratedTransport instanceof SetupableTransportInterface) {
$this->decoratedTransport->setup();
}
}
public function get(): iterable
{
return $this->decoratedTransport->get();
}
public function ack(Envelope $envelope): void
{
$this->decoratedTransport->ack($envelope);
}
public function reject(Envelope $envelope): void
{
$this->decoratedTransport->reject($envelope);
}
public function send(Envelope $envelope): Envelope
{
return $this->decoratedTransport->send($this->addPersistentDeliveryModeToEnvelope($envelope));
}
private function addPersistentDeliveryModeToEnvelope(Envelope $envelope): Envelope
{
/** @var AmqpStamp|null $amqpStamp */
$amqpStamp = $envelope->last(AmqpStamp::class);
$attributes = $amqpStamp ? $amqpStamp->getAttributes() : [];
$attributes['delivery_mode'] = self::DELIVERY_MODE_PERSISTENT;
$amqpStampWithDeliveryMode = new AmqpStamp(
$amqpStamp ? $amqpStamp->getRoutingKey() : null,
$amqpStamp ? $amqpStamp->getFlags() : \AMQP_NOPARAM,
$attributes
);
return $envelope->with($amqpStampWithDeliveryMode);
}
} |