Closed
Description
Symfony version: 4.1.6
Hi, our company is struggling with some messenger configuration problem. We are using messenger component (symfony/amqp-pack included) andRabbitMQ, and everything is working fine, but we want to send messages as persistent - is there some way to setup this configuration by default? Our solution is simple, we wrote custom message transport, and we override sended headers in pusblish method from Connection class:
/**
* @throws \AMQPException
*/
public function publish(string $body, array $headers = array()): void
{
if ($this->debug && $this->shouldSetup()) {
$this->setup();
}
$this->exchange()->publish($body, null, AMQP_NOPARAM, array('delivery_mode' => 2, 'headers' => $headers));
}
configuration example:
# services.yaml
App\Service\Messenger\PAmqpTransport\PAmqpTransportFactory:
tags: [messenger.transport_factory]
bind:
$encoder: '@App\Service\Messenger\PAmqpTransport\Serializer'
$decoder: '@App\Service\Messenger\PAmqpTransport\Serializer'
$debug: false
# messenger.yaml
doctrine: 'pamqp://%env(RABBITMQ_USER)%:%env(RABBITMQ_PASS)%@%env(RABBITMQ_HOST)%:%env(RABBITMQ_PORT)%/%2f/doctrine'
We need to send 'delivery_mode' => 2
, so Rabbit will keep messages persistent, shouldn't be this option possible to setup in configuration?