diff --git a/src/Rejection.php b/src/Rejection.php index f7f6859..579eb29 100644 --- a/src/Rejection.php +++ b/src/Rejection.php @@ -7,8 +7,9 @@ use Bunny\Channel; use Bunny\Client; use Kiboko\Contract\Pipeline\RejectionInterface; +use Kiboko\Contract\Pipeline\RejectionWithReasonInterface; -final readonly class Rejection implements RejectionInterface +final readonly class Rejection implements RejectionInterface, RejectionWithReasonInterface { private Channel $channel; @@ -86,6 +87,23 @@ public function reject(object|array $rejection, ?\Throwable $exception = null): ); } + public function rejectWithReason(object|array $rejection, string $reason, ?\Throwable $exception = null): void + { + $this->channel->publish( + json_encode([ + 'item' => $rejection, + 'reason' => $reason, + 'exception' => $exception, + 'step' => $this->stepUuid, + ], \JSON_THROW_ON_ERROR), + [ + 'content-type' => 'application/json', + ], + $this->exchange, + $this->topic, + ); + } + public function initialize(): void { $this->channel->queueDeclare(