-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected: 4.3
Description
When calling $this->messageBus->dispatch();
on a loop; if for some reason, there is a connectivity issue, preventing from publishing a message in the queue; then the code stops;
Aws\Sqs\Exception\SqsException
Error executing "SendMessage" on "https://sqs.eu-west-2.amazonaws.com/xyxyxyxyxyxy/my-aweome-queue-name"; AWS HTTP error: cURL error 6: Could not resolve host: sqs.eu-west-2.amazonaws.com (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
I think it is bad DX, because we don't except dispatch
to stop code execution until the code on the production tells you it can happen :).
And after it's difficult to know which messages has been correctly sent to the queue and the one that didn't;
So I wrote this instead:
try {
$this->messageBus->dispatch(Message::create());
} catch (\Exception $exception) {
try {
sleep(1);
$this->messageBus->dispatch(KeywordMessage::create());
} catch (\Exception) {
// do nothing so the code still continue to iterate
}
}
The code is not particularly beautiful; but allow at least 1 retry in case of some failure;
-
Should the
message bus
implement some logic to retry sending the message to the queue ? -
should the developper implement and should be encouraged to wrap all calls to
dispatch
in atry/catch
block ? (something similar to what has been done to the Symfony Http Client) -
Or should the libraries/adapters underneath do that ?
I'm using:
sroze/messenger-enqueue-transport
enqueue/sqs
symfony/messenger (v4.3.4)