[Chapter 7] Multiple improvements + Event Handler + Projection + Projection Bus

This commit is contained in:
Carlos Buenosvinos
2022-03-12 12:16:32 +01:00
parent 18fe441b7b
commit a856403b49
12 changed files with 22 additions and 16 deletions

View File

@@ -47,7 +47,6 @@ framework:
# Dead letter box
failed_messages: '%env(MESSENGER_TRANSPORT_BASE_DSN)%/failed_messages'
routing:
# With a proper UX, almost all the commands should
# be run asynchronously.However, some commands can
@@ -69,4 +68,4 @@ framework:
# Projections should run asynchronously by default.
# However, it's possible to run some synchronously
# without getting the performance benefits.
Cheeper\Chapter7\Application\Projection: projections_async
Cheeper\Chapter7\Application\Projection: projections_async

View File

@@ -104,8 +104,11 @@ services:
# class: 'Cheeper\Chapter6\Infrastructure\Application\SymfonyProjectionBus'
# CHAPTER 7
Cheeper\Chapter7\:
resource: '../src/Cheeper/Chapter7/*'
Cheeper\Chapter7\Application\:
resource: '../src/Cheeper/Chapter7/Application/*'
Cheeper\Chapter7\Infrastructure\:
resource: '../src/Cheeper/Chapter7/Infrastructure/*'
Cheeper\Chapter7\DomainModel\Author\AuthorRepository:
class: 'Cheeper\Chapter7\Infrastructure\DomainModel\Author\DoctrineOrmAuthorRepository'
@@ -130,13 +133,13 @@ services:
chapter7_command_handlers:
namespace: Cheeper\Chapter7\Application\
resource: '../src/Cheeper/Chapter7/Application/**/*CommandHandler.php'
resource: '../src/Cheeper/Chapter7/Application/**/Command/*CommandHandler.php'
tags:
- { name: messenger.message_handler, bus: command.bus }
chapter7_event_handlers:
namespace: Cheeper\Chapter7\Application\
resource: '../src/Cheeper/Chapter7/Application/**/Symfony*EventHandler.php'
resource: '../src/Cheeper/Chapter7/Application/**/*EventHandler.php'
tags:
- { name: messenger.message_handler, bus: event.bus }
@@ -148,7 +151,7 @@ services:
chapter7_projection_handlers:
namespace: Cheeper\Chapter7\Application\
resource: '../src/Cheeper/Chapter7/Application/**/Symfony*ProjectionHandler.php'
resource: '../src/Cheeper/Chapter7/Application/**/*ProjectionHandler.php'
tags:
- { name: messenger.message_handler, bus: projection.bus }

View File

@@ -1,17 +1,16 @@
version: '3.9'
services:
redis:
image: redis
ports:
- "6379:6379"
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"
mysql:
image: mysql
image: mariadb
ports:
- "3306:3306"
environment:

View File

@@ -16,7 +16,7 @@ final class AuthorFollowedEventHandler
) {
}
public function handle(AuthorFollowed $event): void
public function __invoke(AuthorFollowed $event): void
{
$this->projectionHandler->__invoke(
CountFollowersProjection::ofAuthor($event->toAuthorId())

View File

@@ -18,7 +18,7 @@ final class NewAuthorSignedEventHandler
) {
}
public function handle(NewAuthorSigned $event): void
public function __invoke(NewAuthorSigned $event): void
{
$this->followersProjector->__invoke(
CreateFollowersCounterProjection::ofAuthor(

View File

@@ -17,7 +17,7 @@ final class WhenNewAuthorSignedThenCreateTimelineProjectionEventHandler
) {
}
public function handle(NewAuthorSigned $event): void
public function __invoke(NewAuthorSigned $event): void
{
$this->projector->__invoke(
CreateTimelineProjection::ofAuthor(

View File

@@ -21,7 +21,7 @@ final class CheepPostedEventHandler
) {
}
public function handle(CheepPosted $event): void
public function __invoke(CheepPosted $event): void
{
$follows = $this->followRepository->toAuthorId(
AuthorId::fromString($event->authorId())

View File

@@ -25,6 +25,7 @@ final class SymfonyAuthorFollowedEventHandler implements MessageSubscriberInterf
{
yield AuthorFollowed::class => [
'method' => 'handle',
'bus' => 'event.bus',
'from_transport' => 'events_async',
];
}

View File

@@ -26,6 +26,7 @@ final class SymfonyNewAuthorSignedEventHandler implements MessageSubscriberInter
{
yield NewAuthorSigned::class => [
'method' => 'handle',
'bus' => 'event.bus',
'from_transport' => 'events_async',
];
}

View File

@@ -25,7 +25,8 @@ final class SymfonyCheepPostedEventHandler implements MessageSubscriberInterface
{
yield CheepPosted::class => [
'method' => 'handle',
'from_transport' => 'chapter7_events',
'bus' => 'event.bus',
'from_transport' => 'events',
];
}
}

View File

@@ -25,7 +25,8 @@ final class SymfonyAddCheepToTimelineProjectionHandler implements MessageSubscri
{
yield AddCheepToTimelineProjection::class => [
'method' => 'handle',
'from_transport' => 'chapter7_async_projections',
'bus' => 'projection.bus',
'from_transport' => 'projections_async',
];
}
}