Skip to content

Commit

Permalink
Restore from DLQ Command (#165)
Browse files Browse the repository at this point in the history
* Command to recover messages from DLQ

* DLQ tool docs
  • Loading branch information
nie7321 authored Feb 6, 2024
1 parent 79e676a commit 34e121b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added

- The `eventhub:dlq:restore-messages` artisan command has been added. This is a tool to move messages from the DLQ back to the original queue for re-processing.

### Changed
- Support for PHP 7.4 and 8.0 has been dropped.
Expand Down
1 change: 1 addition & 0 deletions docs/eventhub.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ You can run these with `php artisan <command>`.
| eventhub:webhook:toggle pause | Pause all webhooks. Optionally, you can pass a list of queue names to pause just those. |
| eventhub:webhook:toggle unpause | Unpause all webhooks. Optionally, you can pass a list of queue names to unpause just those. |
| eventhub:webhook:configure | Publishes the webhook delivery routes configured in your route files with EventHub |
| eventhub:dlq:restore-messages | Moves messages from the DLQ back to the original queue for re-processing. |

## Test Messages
In the dev & test environments, you should have permission to write messages to the queues you're subscribed to via `POST /v1/event-hub/queue/your-queue-name`.
Expand Down
5 changes: 5 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Upgrading

## From v9 to v10
PHP 7.4 & 8.0 support has been dropped.

Some types have been updated. The one that you are likely to run into is `DirectorySearch::lookup(...): array|false`. If you had provided a type when extending this class, a return type of `array|bool` will not be compatible.

## From v8 to v9
PHP 7.3 support was dropped due to necessary dependencies dropping support.

Expand Down
51 changes: 51 additions & 0 deletions src/Console/Commands/EventHub/RestoreMessagesFromDLQ.php
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();
}
}
1 change: 1 addition & 0 deletions src/Providers/NuSoaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function boot()
Commands\EventHub\WebhookStatus::class,
Commands\EventHub\WebhookToggle::class,
Commands\EventHub\WebhookConfiguration::class,
Commands\EventHub\RestoreMessagesFromDLQ::class,

Commands\MakeWebSSO::class,
Commands\ShowOAuthCallbackUrl::class,
Expand Down

0 comments on commit 34e121b

Please sign in to comment.