@@ -140,14 +140,16 @@ private function handleMessage(Envelope $envelope, ReceiverInterface $receiver,
140140
141141 $ this ->dispatchEvent (new WorkerMessageFailedEvent ($ envelope , $ transportName , $ throwable , $ shouldRetry ));
142142
143+ $ retryCount = RedeliveryStamp::getRetryCountFromEnvelope ($ envelope );
143144 if ($ shouldRetry ) {
144- $ retryCount = $ this ->getRetryCount ($ envelope ) + 1 ;
145+ ++$ retryCount ;
146+ $ delay = $ retryStrategy ->getWaitingTime ($ envelope );
145147 if (null !== $ this ->logger ) {
146- $ this ->logger ->error ('Retrying {class} - retry #{retryCount}. ' , $ context + ['retryCount ' => $ retryCount , 'error ' => $ throwable ]);
148+ $ this ->logger ->error ('Error thrown while handling message {class}. Dispatching for retry #{retryCount} using {delay} ms delay. Error: "{error}" ' , $ context + ['retryCount ' => $ retryCount , 'delay ' => $ delay , ' error ' => $ throwable -> getMessage (), ' exception ' => $ throwable ]);
147149 }
148150
149151 // add the delay and retry stamp info + remove ReceivedStamp
150- $ retryEnvelope = $ envelope ->with (new DelayStamp ($ retryStrategy -> getWaitingTime ( $ envelope ) ))
152+ $ retryEnvelope = $ envelope ->with (new DelayStamp ($ delay ))
151153 ->with (new RedeliveryStamp ($ retryCount , $ this ->getSenderClassOrAlias ($ envelope )))
152154 ->withoutAll (ReceivedStamp::class);
153155
@@ -157,7 +159,7 @@ private function handleMessage(Envelope $envelope, ReceiverInterface $receiver,
157159 $ receiver ->ack ($ envelope );
158160 } else {
159161 if (null !== $ this ->logger ) {
160- $ this ->logger ->critical ('Rejecting {class} (removing from transport). ' , $ context + ['error ' => $ throwable ]);
162+ $ this ->logger ->critical ('Error thrown while handling message {class}. Removing from transport after {retryCount} retries. Error: "{error}" ' , $ context + ['retryCount ' => $ retryCount , ' error ' => $ throwable -> getMessage (), ' exception ' => $ throwable ]);
161163 }
162164
163165 $ receiver ->reject ($ envelope );
@@ -167,8 +169,8 @@ private function handleMessage(Envelope $envelope, ReceiverInterface $receiver,
167169 }
168170
169171 $ this ->dispatchEvent (new WorkerMessageHandledEvent ($ envelope , $ transportName ));
170-
171172 if (null !== $ this ->logger ) {
173+
172174 $ this ->logger ->info ('{class} was handled successfully (acknowledging to transport). ' , $ context );
173175 }
174176
@@ -207,14 +209,6 @@ private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInt
207209 return $ retryStrategy ->isRetryable ($ envelope );
208210 }
209211
210- private function getRetryCount (Envelope $ envelope ): int
211- {
212- /** @var RedeliveryStamp|null $retryMessageStamp */
213- $ retryMessageStamp = $ envelope ->last (RedeliveryStamp::class);
214-
215- return $ retryMessageStamp ? $ retryMessageStamp ->getRetryCount () : 0 ;
216- }
217-
218212 private function getSenderClassOrAlias (Envelope $ envelope ): string
219213 {
220214 /** @var SentStamp|null $sentStamp */
0 commit comments