I try to use Symfony/Messenger with a web service. I don't understand why the queue don't retry 3 times when I have a critical error.
This is my messenger configuration:
framework:
messenger:
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
# failure_transport: failed
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
# async: '%env(MESSENGER_TRANSPORT_DSN)%'
# failed: 'doctrine://default?queue_name=failed'
# sync: 'sync://'
async_sms:
dsn: 'doctrine://default?auto_setup=0&table_name=ec2_messenger_messages'
options:
queue_name: 'async_sms'
retry_strategy:
max_retries: 3
delay: 30000
multiplier: 2
max_delay: 0
routing:
# Route your messages to the transports
# 'App\Message\YourMessage': async
'App\Message\Sms': async_sms
Basically, I have define the default configuration to force to retry when it fails.
This is my Message object (very basic implementation) :
namespace App\Message;
class Sms
{
/**
* @param string $content
* @param int $addresseeId
* @param int $companyDivisionId
*/
public function __construct(
private string $content,
private int $addresseeId,
private int $companyDivisionId
)
{}
/**
* @return string
*/
public function getContent(): string
{
return $this->content;
}
/**
* @return int
*/
public function getAddresseeId(): int
{
return $this->addresseeId;
}
/**
* @return int
*/
public function getCompanyDivisionId(): int
{
return $this->companyDivisionId;
}
}
This is my MessageHandler (call the manager which use the web service & Doctrine service):
class SmsHandler
{
/**
* @param UserRepository $userRepository
* @param CompanyDivisionRepository $companyDivisionRepository
* @param OvhClientManager $ovhClientManager
*/
public function __construct(
private UserRepository $userRepository,
private CompanyDivisionRepository $companyDivisionRepository,
private OvhClientManager $ovhClientManager
) {}
/**
* @param Sms $sms
* @return void
*/
public function __invoke(Sms $sms): void
{
$user = $this->userRepository->findOneBy(['id' => $sms->getAddresseeId()]);
$companyDivision = $this->companyDivisionRepository->findOneBy(['id' => $sms->getCompanyDivisionId()]);
$this->ovhClientManager->sendSms($sms->getContent(), $user, $companyDivision);
}
}
Do you have an explanation about this problem ?