-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ndthuan/enable-logic-overrides
Introduce callbacks for subscriber
- Loading branch information
Showing
9 changed files
with
211 additions
and
48 deletions.
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
Empty file.
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,84 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Ndthuan\AwsSqsWrapper\Subscribing\Callbacks; | ||
|
||
use Ndthuan\AwsSqsWrapper\Queue\ReceivedMessage; | ||
use Ndthuan\AwsSqsWrapper\Subscribing\Exception\FatalException; | ||
use Ndthuan\AwsSqsWrapper\Subscribing\Exception\LogicException; | ||
use Psr\Log\LoggerInterface; | ||
use Throwable; | ||
|
||
/** | ||
* Class LoggingCallbacks | ||
*/ | ||
class LoggingCallbacks implements SubscriberCallbacksInterface | ||
{ | ||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* LoggingCallbacks constructor. | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
*/ | ||
public function onMessageReceived(ReceivedMessage $message) | ||
{ | ||
$this->logger->info('Received SQS message', ['messageId' => $message->getId()]); | ||
} | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
*/ | ||
public function onMessageProcessed(ReceivedMessage $message) | ||
{ | ||
$this->logger->info('Successfully processed SQS message', [ | ||
'messageId' => $message->getId(), | ||
]); | ||
} | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
* @param LogicException $exception | ||
*/ | ||
public function onLogicException(ReceivedMessage $message, LogicException $exception) | ||
{ | ||
$this->logger->info('Deleted SQS message due to logical exception', [ | ||
'messageId' => $message->getId(), | ||
'exception' => $exception, | ||
]); | ||
} | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
* @param FatalException $exception | ||
*/ | ||
public function onFatalException(ReceivedMessage $message, FatalException $exception) | ||
{ | ||
$this->logger->critical('Stopped SQS processing due to fatal exception', [ | ||
'messageId' => $message->getId(), | ||
'exception' => $exception, | ||
]); | ||
} | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
* @param Throwable $exception | ||
*/ | ||
public function onUncaughtException(ReceivedMessage $message, Throwable $exception) | ||
{ | ||
$this->logger->error('Uncaught exception when processing SQS message', [ | ||
'messageId' => $message->getId(), | ||
'exception' => $exception, | ||
]); | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Ndthuan\AwsSqsWrapper\Subscribing\Callbacks; | ||
|
||
use Ndthuan\AwsSqsWrapper\Queue\ReceivedMessage; | ||
use Ndthuan\AwsSqsWrapper\Subscribing\Exception\FatalException; | ||
use Ndthuan\AwsSqsWrapper\Subscribing\Exception\LogicException; | ||
use Throwable; | ||
|
||
/** | ||
* Class NullCallbacks | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
class NullCallbacks implements SubscriberCallbacksInterface | ||
{ | ||
/** | ||
* @param ReceivedMessage $message | ||
*/ | ||
public function onMessageReceived(ReceivedMessage $message) | ||
{ | ||
} | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
*/ | ||
public function onMessageProcessed(ReceivedMessage $message) | ||
{ | ||
} | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
* @param LogicException $exception | ||
*/ | ||
public function onLogicException(ReceivedMessage $message, LogicException $exception) | ||
{ | ||
} | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
* @param FatalException $exception | ||
*/ | ||
public function onFatalException(ReceivedMessage $message, FatalException $exception) | ||
{ | ||
} | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
* @param Throwable $exception | ||
*/ | ||
public function onUncaughtException(ReceivedMessage $message, Throwable $exception) | ||
{ | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/Subscribing/Callbacks/SubscriberCallbacksInterface.php
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,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Ndthuan\AwsSqsWrapper\Subscribing\Callbacks; | ||
|
||
use Ndthuan\AwsSqsWrapper\Queue\ReceivedMessage; | ||
use Ndthuan\AwsSqsWrapper\Subscribing\Exception\FatalException; | ||
use Ndthuan\AwsSqsWrapper\Subscribing\Exception\LogicException; | ||
use Throwable; | ||
|
||
/** | ||
* Interface SubscriberCallbacksInterface | ||
* | ||
* Subscriber callback methods. | ||
*/ | ||
interface SubscriberCallbacksInterface | ||
{ | ||
/** | ||
* @param ReceivedMessage $message | ||
*/ | ||
public function onMessageReceived(ReceivedMessage $message); | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
*/ | ||
public function onMessageProcessed(ReceivedMessage $message); | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
* @param LogicException $exception | ||
*/ | ||
public function onLogicException(ReceivedMessage $message, LogicException $exception); | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
* @param FatalException $exception | ||
*/ | ||
public function onFatalException(ReceivedMessage $message, FatalException $exception); | ||
|
||
/** | ||
* @param ReceivedMessage $message | ||
* @param Throwable $exception | ||
*/ | ||
public function onUncaughtException(ReceivedMessage $message, Throwable $exception); | ||
} |
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