Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Plugin/HandleQueueMessageRejectPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace RunAsRoot\MessageQueueRetry\Plugin;

use JsonException;
use Magento\Framework\MessageQueue\EnvelopeInterface;
use Magento\Framework\MessageQueue\QueueInterface;
use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeCreatedException;
use RunAsRoot\MessageQueueRetry\Service\IsMessageShouldBeSavedForRetryService;
use RunAsRoot\MessageQueueRetry\Service\SaveFailedMessageService;

class HandleQueueMessageRejectPlugin
{
public function __construct(
private IsMessageShouldBeSavedForRetryService $isMessageShouldBeSavedForRetryService,
private SaveFailedMessageService $saveFailedMessageService
) {
}

/**
* @throws MessageCouldNotBeCreatedException
* @throws JsonException
*/
public function aroundReject(
QueueInterface $subject,
callable $proceed,
EnvelopeInterface $envelope,
bool $requeue,
string $error
): void {
if (!$error) {
$proceed($envelope, $requeue, $error);
return;
}

$shouldBeSavedForRetry = $this->isMessageShouldBeSavedForRetryService->execute($envelope);

if (!$shouldBeSavedForRetry) {
$proceed($envelope, $requeue, $error);
return;
}

$this->saveFailedMessageService->execute($envelope, $error);
$subject->acknowledge($envelope);
}
}
181 changes: 0 additions & 181 deletions src/Queue/Consumer.php

This file was deleted.

28 changes: 28 additions & 0 deletions src/Service/GetMessageRetriesCountService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace RunAsRoot\MessageQueueRetry\Service;

use Magento\Framework\MessageQueue\EnvelopeInterface;
use PhpAmqpLib\Wire\AMQPTable;

class GetMessageRetriesCountService
{
public function execute(EnvelopeInterface $message): int
{
$messageProperties = $message->getProperties();
$applicationHeaders = $messageProperties['application_headers'] ?? null;

// If there are no application headers, then it is the first time the message has been processed.
if (!$applicationHeaders instanceof AMQPTable) {
return 0;
}

if (isset($applicationHeaders->getNativeData()['x-death'][0]['count'])) {
return $applicationHeaders->getNativeData()['x-death'][0]['count'];
}

return 0;
}
}
104 changes: 0 additions & 104 deletions src/Service/HandleQueueFailureService.php

This file was deleted.

Loading