|
I'm using Symfony/6.4.35 LTS with PHP/8.4.18. I need to send a message to an AWS SQS queue (emulated with ElasticMQ in my development environment). The queue has a delay that will be established by DevOps. If I set a per-message delay, it overrides the queue default: $this->messageBus->dispatch(
new FooMessage('blah'),
[new DelayStamp(15 * 60 * 1000)]
);If I don't set it, turns out $this->messageBus->dispatch(
new FooMessage('blah')
);// \Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsSender::send()
/** @var DelayStamp|null $delayStamp */
$delayStamp = $envelope->last(DelayStamp::class);
$delay = null !== $delayStamp ? (int) ceil($delayStamp->getDelay() / 1000) : 0;
// ...
try {
$this->connection->send(
$encodedMessage['body'],
$encodedMessage['headers'] ?? [],
$delay,
$messageGroupId,
$messageDeduplicationId,
$xrayTraceId
);
} catch (HttpException $e) {
throw new TransportException($e->getMessage(), 0, $e);
}// \Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection::send()
public function send(string $body, array $headers, int $delay = 0, ?string $messageGroupId = null, ?string $messageDeduplicationId = null, ?string $xrayTraceId = null): void
// ...
$parameters = [
'QueueUrl' => $this->getQueueUrl(),
'MessageBody' => $body,
// Maximum delay is 15 minutes. See https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-timers.html.
'DelaySeconds' => min(900, $delay),
'MessageAttributes' => [],
'MessageSystemAttributes' => [],
];If don't have this problem if I use AWS PHP SDK to send the message. Is it possible to configure Symfony Messenger to send messages using the queue default delay? |
Replies: 3 comments
|
I found a pull request so I presume there is no such feature, but I wonder if there's a workaround of some kind. |
|
The direct answer is: if Symfony's SQS sender sends In SQS, the queue-level delay is the fallback only when the send request does not specify a per-message delay. Once So there are basically three options:
The clean operational setup is often: transports:
async: '%env(MESSENGER_SQS_DSN)%'
async_delayed: '%env(MESSENGER_DELAYED_SQS_DSN)%'Then route messages intentionally instead of relying on implicit default delay behavior. So if the current Messenger transport always sends |
|
FWIW, the fix was merged 2 weeks ago and, to my understanding, it should be available in these releases:
|
FWIW, the fix was merged 2 weeks ago and, to my understanding, it should be available in these releases: