diff --git a/packages/Dbal/src/Recoverability/DbalDeadLetterConsoleCommand.php b/packages/Dbal/src/Recoverability/DbalDeadLetterConsoleCommand.php index 6fe9fae3a..5a7a5e0e2 100644 --- a/packages/Dbal/src/Recoverability/DbalDeadLetterConsoleCommand.php +++ b/packages/Dbal/src/Recoverability/DbalDeadLetterConsoleCommand.php @@ -2,6 +2,7 @@ namespace Ecotone\Dbal\Recoverability; +use Ecotone\Api\Attribute\ConsoleParameterOption; use Ecotone\Api\Console\ConsoleCommandResultSet; use Ecotone\Api\Dbal\Gateway\DeadLetterGateway; use Ecotone\Api\Messaging\ErrorContext; @@ -21,8 +22,8 @@ public function help(): ConsoleCommandResultSet [ [DbalDeadLetterModule::LIST_COMMAND_NAME . ' {page:int}', 'List all dead messages'], [DbalDeadLetterModule::SHOW_COMMAND_NAME . ' {messageId:string} {fullDetails:bool}', 'Show more details about specific message'], - [DbalDeadLetterModule::REPLAY_COMMAND_NAME . ' {messageId:string} {targetChannel:?string}', 'Replay chosen dead message, to its source channel or to the target channel'], - [DbalDeadLetterModule::REPLAY_ALL_COMMAND_NAME . ' {targetChannel:?string}', 'Replay ALL dead messages, to their source channels or to the target channel'], + [DbalDeadLetterModule::REPLAY_COMMAND_NAME . ' {messageId:string} {--targetChannel=}', 'Replay chosen dead message, to its source channel or to the target channel'], + [DbalDeadLetterModule::REPLAY_ALL_COMMAND_NAME . ' {--targetChannel=}', 'Replay ALL dead messages, to their source channels or to the target channel'], [DbalDeadLetterModule::DELETE_COMMAND_NAME . ' {messageId:string}', 'Delete chosen dead message'], ] ); @@ -65,7 +66,7 @@ public function show(DeadLetterGateway $deadLetterGateway, string $messageId, bo ); } - public function replay(DeadLetterGateway $deadLetterGateway, string $messageId, ?string $targetChannel = null): void + public function replay(DeadLetterGateway $deadLetterGateway, string $messageId, #[ConsoleParameterOption] ?string $targetChannel = null): void { $deadLetterGateway->replay($messageId, $targetChannel); } @@ -75,7 +76,7 @@ public function delete(DeadLetterGateway $deadLetterGateway, string $messageId): $deadLetterGateway->delete($messageId); } - public function replayAll(DeadLetterGateway $deadLetterGateway, ?string $targetChannel = null): void + public function replayAll(DeadLetterGateway $deadLetterGateway, #[ConsoleParameterOption] ?string $targetChannel = null): void { $deadLetterGateway->replayAll($targetChannel); } diff --git a/packages/Dbal/tests/Integration/DeadLetterTest.php b/packages/Dbal/tests/Integration/DeadLetterTest.php index 36ee7f5e8..0d881f3ca 100644 --- a/packages/Dbal/tests/Integration/DeadLetterTest.php +++ b/packages/Dbal/tests/Integration/DeadLetterTest.php @@ -359,6 +359,7 @@ public function test_all_dead_letter_messages_are_replayed_to_the_chosen_channel $handler = new class () { public const TARGET_CHANNEL = 'allTargetChannel'; + public int $sourceInvocations = 0; /** @var string[] */ public array $handledByTarget = []; private bool $hasEmitted = false; @@ -378,6 +379,8 @@ public function emit(): ?string #[\Ecotone\Api\Attribute\InternalHandler('allSourceChannel')] public function handleBySource(string $payload): void { + $this->sourceInvocations++; + throw new RuntimeException('simulated'); } @@ -410,6 +413,7 @@ classesToResolve: [$handler::class], $ecotone->getGateway(DeadLetterGateway::class)->replayAll($handler::TARGET_CHANNEL); $this->assertErrorMessageCount($ecotone, 0); + $this->assertSame(1, $handler->sourceInvocations); $this->assertSame(['payload'], $handler->handledByTarget); } @@ -483,6 +487,7 @@ public function test_console_command_replays_dead_letter_message_to_the_chosen_c $handler = new class () { public const TARGET_CHANNEL = 'consoleTargetChannel'; + public int $sourceInvocations = 0; /** @var string[] */ public array $handledByTarget = []; private bool $hasEmitted = false; @@ -502,6 +507,8 @@ public function emit(): ?string #[\Ecotone\Api\Attribute\InternalHandler('consoleSourceChannel')] public function handleBySource(string $payload): void { + $this->sourceInvocations++; + throw new RuntimeException('simulated'); } @@ -535,6 +542,7 @@ classesToResolve: [$handler::class], $ecotone->runConsoleCommand('ecotone:deadletter:replay', ['messageId' => $messageId, 'targetChannel' => $handler::TARGET_CHANNEL]); $this->assertErrorMessageCount($ecotone, 0); + $this->assertSame(1, $handler->sourceInvocations); $this->assertSame(['payload'], $handler->handledByTarget); }