-
Notifications
You must be signed in to change notification settings - Fork 5
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 #491 from patchlevel/add-consumer
extract consumer logic and rename outbox consumer into processor
- Loading branch information
Showing
17 changed files
with
231 additions
and
237 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
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\EventBus; | ||
|
||
interface Consumer | ||
{ | ||
public function consume(Message $message): void; | ||
} |
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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\EventBus; | ||
|
||
use Psr\Log\LoggerInterface; | ||
|
||
use function sprintf; | ||
|
||
final class DefaultConsumer implements Consumer | ||
{ | ||
public function __construct( | ||
private readonly ListenerProvider $listenerProvider, | ||
private readonly LoggerInterface|null $logger = null, | ||
) { | ||
} | ||
|
||
public function consume(Message $message): void | ||
{ | ||
$eventClass = $message->event()::class; | ||
|
||
$this->logger?->debug(sprintf( | ||
'EventBus: Consume message "%s".', | ||
$eventClass, | ||
)); | ||
|
||
$listeners = $this->listenerProvider->listenersForEvent($eventClass); | ||
|
||
foreach ($listeners as $listener) { | ||
$this->logger?->info(sprintf( | ||
'EventBus: Listener "%s" consume message with event "%s".', | ||
$listener->name(), | ||
$eventClass, | ||
)); | ||
|
||
($listener->callable())($message); | ||
} | ||
} | ||
|
||
/** @param iterable<object> $listeners */ | ||
public static function create(iterable $listeners = []): self | ||
{ | ||
return new self(new AttributeListenerProvider($listeners)); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Outbox; | ||
|
||
interface OutboxProcessor | ||
{ | ||
public function process(int|null $limit = null): void; | ||
} |
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
Oops, something went wrong.