From b366f7e321261f8d27e6c9d3d70575dd6a2a3d7c Mon Sep 17 00:00:00 2001 From: David Badura Date: Tue, 6 Feb 2024 12:49:25 +0100 Subject: [PATCH] rename outbox consumer into processor --- docs/pages/outbox.md | 17 +++++++++++------ src/Console/Command/OutboxConsumeCommand.php | 6 +++--- src/Outbox/OutboxConsumer.php | 10 ---------- src/Outbox/OutboxProcessor.php | 10 ++++++++++ ...boxConsumer.php => StoreOutboxProcessor.php} | 4 ++-- tests/Integration/Outbox/OutboxTest.php | 6 +++--- .../Command/OutboxConsumeCommandTest.php | 10 +++++----- tests/Unit/Outbox/StoreOutboxConsumerTest.php | 12 ++++++------ 8 files changed, 40 insertions(+), 35 deletions(-) delete mode 100644 src/Outbox/OutboxConsumer.php create mode 100644 src/Outbox/OutboxProcessor.php rename src/Outbox/{StoreOutboxConsumer.php => StoreOutboxProcessor.php} (79%) diff --git a/docs/pages/outbox.md b/docs/pages/outbox.md index 9d0a848c1..4404a538d 100644 --- a/docs/pages/outbox.md +++ b/docs/pages/outbox.md @@ -23,12 +23,12 @@ This stores the events to be dispatched in the database. use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager; use Patchlevel\EventSourcing\Outbox\OutboxEventBus; -$outboxEventBus = new OutboxEventBus($store); +$eventBus = new OutboxEventBus($store); $repositoryManager = new DefaultRepositoryManager( $aggregateRootRegistry, $store, - $outboxEventBus + $eventBus ); ``` @@ -36,15 +36,20 @@ And then you have to define the consumer. This gets the right event bus. It is used to load the events to be dispatched from the database, dispatch the events and then empty the outbox table. ```php +use Patchlevel\EventSourcing\EventBus\DefaultConsumer; use Patchlevel\EventSourcing\Outbox\EventBusPublisher; -use Patchlevel\EventSourcing\Outbox\StoreOutboxConsumer; +use Patchlevel\EventSourcing\Outbox\StoreOutboxProcessor; -$consumer = new StoreOutboxConsumer( +$consumer = DefaultConsumer::create([ + $mailListener, +]); + +$processor = new StoreOutboxProcessor( $store, - new EventBusPublisher($realEventBus) + new EventBusPublisher($consumer) ); -$consumer->consume(); +$processor->process(); ``` ## Using outbox diff --git a/src/Console/Command/OutboxConsumeCommand.php b/src/Console/Command/OutboxConsumeCommand.php index 33a0c0ae9..484ac68a8 100644 --- a/src/Console/Command/OutboxConsumeCommand.php +++ b/src/Console/Command/OutboxConsumeCommand.php @@ -5,7 +5,7 @@ namespace Patchlevel\EventSourcing\Console\Command; use Patchlevel\EventSourcing\Console\InputHelper; -use Patchlevel\EventSourcing\Outbox\OutboxConsumer; +use Patchlevel\EventSourcing\Outbox\OutboxProcessor; use Patchlevel\Worker\DefaultWorker; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -21,7 +21,7 @@ final class OutboxConsumeCommand extends Command { public function __construct( - private readonly OutboxConsumer $consumer, + private readonly OutboxProcessor $processor, ) { parent::__construct(); } @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $worker = DefaultWorker::create( function () use ($messageLimit): void { - $this->consumer->consume($messageLimit); + $this->processor->process($messageLimit); }, [ 'runLimit' => $runLimit, diff --git a/src/Outbox/OutboxConsumer.php b/src/Outbox/OutboxConsumer.php deleted file mode 100644 index 3642bd919..000000000 --- a/src/Outbox/OutboxConsumer.php +++ /dev/null @@ -1,10 +0,0 @@ -store->retrieveOutboxMessages($limit); diff --git a/tests/Integration/Outbox/OutboxTest.php b/tests/Integration/Outbox/OutboxTest.php index baacc3923..5781abcd6 100644 --- a/tests/Integration/Outbox/OutboxTest.php +++ b/tests/Integration/Outbox/OutboxTest.php @@ -9,7 +9,7 @@ use Patchlevel\EventSourcing\Outbox\DoctrineOutboxStore; use Patchlevel\EventSourcing\Outbox\EventBusPublisher; use Patchlevel\EventSourcing\Outbox\OutboxEventBus; -use Patchlevel\EventSourcing\Outbox\StoreOutboxConsumer; +use Patchlevel\EventSourcing\Outbox\StoreOutboxProcessor; use Patchlevel\EventSourcing\Projection\Projection\ProjectionCriteria; use Patchlevel\EventSourcing\Projection\Projection\Store\InMemoryStore; use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist; @@ -116,12 +116,12 @@ public function testSuccessful(): void $message->event(), ); - $consumer = new StoreOutboxConsumer( + $consumer = new StoreOutboxProcessor( $outboxStore, new EventBusPublisher($eventBusConsumer), ); - $consumer->consume(); + $consumer->process(); self::assertSame(0, $outboxStore->countOutboxMessages()); self::assertCount(0, $outboxStore->retrieveOutboxMessages()); diff --git a/tests/Unit/Console/Command/OutboxConsumeCommandTest.php b/tests/Unit/Console/Command/OutboxConsumeCommandTest.php index 03e2f4abe..67be7b31d 100644 --- a/tests/Unit/Console/Command/OutboxConsumeCommandTest.php +++ b/tests/Unit/Console/Command/OutboxConsumeCommandTest.php @@ -5,7 +5,7 @@ namespace Patchlevel\EventSourcing\Tests\Unit\Console\Command; use Patchlevel\EventSourcing\Console\Command\OutboxConsumeCommand; -use Patchlevel\EventSourcing\Outbox\OutboxConsumer; +use Patchlevel\EventSourcing\Outbox\OutboxProcessor; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\Console\Input\ArrayInput; @@ -18,8 +18,8 @@ final class OutboxConsumeCommandTest extends TestCase public function testSuccessful(): void { - $consumer = $this->prophesize(OutboxConsumer::class); - $consumer->consume(100)->shouldBeCalled(); + $consumer = $this->prophesize(OutboxProcessor::class); + $consumer->process(100)->shouldBeCalled(); $command = new OutboxConsumeCommand( $consumer->reveal(), @@ -35,8 +35,8 @@ public function testSuccessful(): void public function testSuccessfulWithAllLimits(): void { - $consumer = $this->prophesize(OutboxConsumer::class); - $consumer->consume(200)->shouldBeCalled(); + $consumer = $this->prophesize(OutboxProcessor::class); + $consumer->process(200)->shouldBeCalled(); $command = new OutboxConsumeCommand( $consumer->reveal(), diff --git a/tests/Unit/Outbox/StoreOutboxConsumerTest.php b/tests/Unit/Outbox/StoreOutboxConsumerTest.php index 925591fbe..70a3262b1 100644 --- a/tests/Unit/Outbox/StoreOutboxConsumerTest.php +++ b/tests/Unit/Outbox/StoreOutboxConsumerTest.php @@ -7,14 +7,14 @@ use Patchlevel\EventSourcing\EventBus\Message; use Patchlevel\EventSourcing\Outbox\OutboxPublisher; use Patchlevel\EventSourcing\Outbox\OutboxStore; -use Patchlevel\EventSourcing\Outbox\StoreOutboxConsumer; +use Patchlevel\EventSourcing\Outbox\StoreOutboxProcessor; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; -/** @covers \Patchlevel\EventSourcing\Outbox\StoreOutboxConsumer */ +/** @covers \Patchlevel\EventSourcing\Outbox\StoreOutboxProcessor */ final class StoreOutboxConsumerTest extends TestCase { use ProphecyTrait; @@ -35,8 +35,8 @@ public function testConsume(): void $eventBus = $this->prophesize(OutboxPublisher::class); $eventBus->publish($message)->shouldBeCalled(); - $consumer = new StoreOutboxConsumer($store->reveal(), $eventBus->reveal()); - $consumer->consume(); + $consumer = new StoreOutboxProcessor($store->reveal(), $eventBus->reveal()); + $consumer->process(); } public function testConsumeWithLimit(): void @@ -55,7 +55,7 @@ public function testConsumeWithLimit(): void $eventBus = $this->prophesize(OutboxPublisher::class); $eventBus->publish($message)->shouldBeCalled(); - $consumer = new StoreOutboxConsumer($store->reveal(), $eventBus->reveal()); - $consumer->consume(100); + $consumer = new StoreOutboxProcessor($store->reveal(), $eventBus->reveal()); + $consumer->process(100); } }