|
2 | 2 |
|
3 | 3 | namespace Smartbox\Integration\FrameworkBundle\Core\Handlers; |
4 | 4 |
|
| 5 | +use Smartbox\Integration\FrameworkBundle\Components\WebService\Rest\Exceptions\UnrecoverableRestException; |
5 | 6 | use Smartbox\Integration\FrameworkBundle\Configurability\Routing\InternalRouter; |
6 | 7 | use Smartbox\Integration\FrameworkBundle\Core\Endpoints\EndpointFactory; |
7 | 8 | use Smartbox\Integration\FrameworkBundle\Core\Endpoints\EndpointInterface; |
8 | 9 | use Smartbox\Integration\FrameworkBundle\Core\Exchange; |
9 | 10 | use Smartbox\Integration\FrameworkBundle\Core\Messages\Context; |
10 | 11 | use Smartbox\Integration\FrameworkBundle\Core\Messages\DeferredExchangeEnvelope; |
| 12 | +use Smartbox\Integration\FrameworkBundle\Core\Messages\DelayedExchangeEnvelope; |
11 | 13 | use Smartbox\Integration\FrameworkBundle\Core\Messages\ErrorExchangeEnvelope; |
12 | 14 | use Smartbox\Integration\FrameworkBundle\Core\Messages\ExchangeEnvelope; |
13 | 15 | use Smartbox\Integration\FrameworkBundle\Core\Messages\FailedExchangeEnvelope; |
14 | 16 | use Smartbox\Integration\FrameworkBundle\Core\Messages\MessageInterface; |
15 | 17 | use Smartbox\Integration\FrameworkBundle\Core\Messages\RetryExchangeEnvelope; |
16 | 18 | use Smartbox\Integration\FrameworkBundle\Core\Messages\ThrottledExchangeEnvelope; |
| 19 | +use Smartbox\Integration\FrameworkBundle\Core\Processors\Exceptions\DelayException; |
17 | 20 | use Smartbox\Integration\FrameworkBundle\Core\Processors\Exceptions\ProcessingException; |
18 | 21 | use Smartbox\Integration\FrameworkBundle\Core\Processors\Exceptions\ThrottledException; |
19 | 22 | use Smartbox\Integration\FrameworkBundle\Core\Processors\Processor; |
@@ -405,6 +408,13 @@ public function onHandleException( |
405 | 408 | $this->dispatchEvent($exchangeBackup, HandlerEvent::THROTTLING_HANDLE_EVENT_NAME); |
406 | 409 |
|
407 | 410 | } // If it's an exchange that can be retried later but it's failing due to an error |
| 411 | + elseif ($originalException instanceof DelayException) { |
| 412 | + $delayPeriod = $exchangeBackup->getIn()->getHeader('delay'); |
| 413 | + $delayExchangeEnvelope = new DelayedExchangeEnvelope($exchangeBackup, $delayPeriod); |
| 414 | + |
| 415 | + $fromQueue = $exchangeBackup->getHeader('from'); |
| 416 | + $this->deferExchangeMessage($delayExchangeEnvelope, $fromQueue); |
| 417 | + } |
408 | 418 | elseif ($originalException instanceof RecoverableExceptionInterface && $retries < $this->retriesMax) { |
409 | 419 |
|
410 | 420 | $retryExchangeEnvelope = new RetryExchangeEnvelope($exchangeBackup, $exception->getProcessingContext(), $retries + 1); |
@@ -543,6 +553,10 @@ public function handle(MessageInterface $message, EndpointInterface $endpointFro |
543 | 553 |
|
544 | 554 | return; |
545 | 555 | } |
| 556 | + } elseif ($message instanceof DelayedExchangeEnvelope) { |
| 557 | + $headers = $message->getBody()->getIn()->getHeaders(); |
| 558 | + unset($headers['delay']); |
| 559 | + $message->getBody()->getIn()->setHeaders($headers); |
546 | 560 | } |
547 | 561 | } |
548 | 562 | // Otherwise create the exchange |
|
0 commit comments