-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Command to recover messages from DLQ * DLQ tool docs
- Loading branch information
Showing
5 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Northwestern\SysDev\SOA\Console\Commands\EventHub; | ||
|
||
use Illuminate\Console\Command; | ||
use Northwestern\SysDev\SOA\EventHub\DeadLetterQueue; | ||
|
||
class RestoreMessagesFromDLQ extends Command | ||
{ | ||
protected $signature = 'eventhub:dlq:restore-messages {dlqName} {maxNumber}'; | ||
|
||
protected $description = 'Move messages from DLQ back to the active queue for re-processing.'; | ||
|
||
public function __construct( | ||
protected DeadLetterQueue $dlqApi, | ||
) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function handle(): int | ||
{ | ||
$dlqName = $this->argument('dlqName'); | ||
$max = (int) $this->argument('maxNumber'); | ||
|
||
for ($i = 0; $i<$max; $i++) { | ||
$this->info("Processing message #{$i}...\n"); | ||
|
||
$id = $this->returnOldestMessage($dlqName); | ||
$this->info("\tProcessed Message ID '{$id}'\n"); | ||
$this->newLine(); | ||
} | ||
|
||
$this->info("Completed processing!\n"); | ||
return self::SUCCESS; | ||
} | ||
|
||
/** | ||
* Returns the oldest message in a DLQ back to its actual queue for redelivery. | ||
* | ||
* @return string|null Processed Message ID, or null if there's nothing left. | ||
*/ | ||
protected function returnOldestMessage(string $queueName): ?string | ||
{ | ||
$message = $this->dlqApi->readOldest($queueName, acknowledge: false); | ||
|
||
$this->dlqApi->moveFromDLQ($queueName, $message->getId(), $queueName); | ||
|
||
return $message->getId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters