Chapter6: Adding RabbitMQ

This commit is contained in:
Carlos Buenosvinos
2021-08-17 13:26:18 +02:00
parent aaf8107ad9
commit 8099962280
5 changed files with 14 additions and 11 deletions

3
.env
View File

@@ -34,7 +34,8 @@ CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
MESSENGER_TRANSPORT_BASE_DSN=amqp://guest:guest@localhost:5672/%2f
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=doctrine://default
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
###< symfony/messenger ###

View File

@@ -15,22 +15,23 @@ framework:
middleware:
- validation
event.bus:
default_middleware: allow_no_handlers
middleware:
- doctrine_ping_connection
- doctrine_close_connection
- doctrine_transaction
- validation
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
events: 'sync://'
events:
dsn: '%env(MESSENGER_TRANSPORT_BASE_DSN)%/events'
# failed: 'doctrine://default?queue_name=failed'
sync: 'sync://'
routing:
# One way to route the messages is using Interfaces or Parent Classes
# that helps on not having to maintaining this routing 1 to 1 approach
Cheeper\Chapter6\Application\Projector\Author\CountFollowers: async
Cheeper\Chapter6\Application\Projector\Author\CountFollowers: sync
# Cheeper\Chapter6\Application\Projector\Author\CountFollowers: events
# 'Cheeper\Chapter5\Application\Query\CountFollowers': sync
# 'Cheeper\DomainModel\DomainEvent': async
Cheeper\DomainModel\DomainEvent: events
# 'Cheeper\Application\Command\AsyncCommand': async
# 'Cheeper\Application\Command\SyncCommand': sync

View File

@@ -13,12 +13,13 @@ services:
- 9200:9200
- 9300:9300
rabbitmq:
image: rabbitmq
image: rabbitmq:3-management
ports:
- 4369:4369
- 5671:5671
- 5672:5672
- 25672:25672
- 15672:15672
mysql:
image: mysql
command: --default-authentication-plugin=mysql_native_password

View File

@@ -21,7 +21,7 @@ final class SymfonyEventBus implements EventBus
public function notify(DomainEvent $event): void
{
$this->handle($event);
$this->messageBus->dispatch($event);
}
public function notifyAll(array $domainEvents): void

View File

@@ -39,8 +39,8 @@ final class DoctrineOrmFollows implements Follows
public function ofFromAuthorIdAndToAuthorId(AuthorId $fromAuthorId, AuthorId $toAuthorId): ?Follow
{
return $this->repository->findOneBy([
'fromAuthorId' => $fromAuthorId,
'toAuthorId' => $toAuthorId
'fromAuthorId.id' => $fromAuthorId,
'toAuthorId.id' => $toAuthorId
]);
}
}