Skip to content

Commit

Permalink
Establish connection to producer app
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuuKodex committed Dec 21, 2023
1 parent cdb5c07 commit 776b531
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 20 deletions.
27 changes: 14 additions & 13 deletions app/config/packages/messenger.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
framework:
messenger:
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
# failure_transport: failed

transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
async_users:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
external_messages:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
options:
auto_setup: true
exchange:
name: messages
type: direct
default_publish_routing_key: from_external
queues:
messages:
binding_keys: [ from_external ]

routing:
'App\Command\CreateUserCommand': async

# when@test:
# framework:
# messenger:
# transports:
# # replace with your transport name here (e.g., my_transport: 'in-memory://')
# # For more Messenger testing tools, see https://github.com/zenstruck/messenger-test
# async: 'in-memory://'
'App\Message\UserInfo': async_users
4 changes: 2 additions & 2 deletions app/src/Controller/CreateDummyUserAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace App\Controller;

use App\Command\CreateUserCommand;
use App\Form\Dto\UserDto;
use App\Form\Type\UserType;
use App\Message\CreateUser;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -26,7 +26,7 @@ public function __invoke(Request $request, MessageBusInterface $messageBus): Res
if ($form->isSubmitted() && $form->isValid()) {
$userDto = $form->getData();

$command = new CreateUserCommand($userDto->getFirstName(), $userDto->getSurname(), $userDto->getEmail());
$command = new CreateUser($userDto->getFirstName(), $userDto->getSurname(), $userDto->getEmail());

$messageBus->dispatch($command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace App\Command;
namespace App\Message;

final readonly class CreateUserCommand
final readonly class CreateUser
{
public function __construct(
private string $firstName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Command;
namespace App\Message;

use App\Entity\User;
use App\Repository\UserRepositoryInterface;
Expand All @@ -14,7 +14,7 @@
{
public function __construct(private UserRepositoryInterface $repository) {}

public function __invoke(CreateUserCommand $command): void
public function __invoke(CreateUser $command): void
{
$user = new User(Uuid::v4(), $command->getFirstName(), $command->getSurname(), $command->getEmail());

Expand Down
19 changes: 19 additions & 0 deletions app/src/Message/UserInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Message;

use App\Entity\User;

final readonly class UserInfo
{
public function __construct(
private User $user
) {}

public function getUser(): User
{
return $this->user;
}
}
27 changes: 27 additions & 0 deletions app/src/Message/UserInfoHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Message;

use App\Entity\User;
use App\Repository\UserRepositoryInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class UserInfoHandler
{
public function __construct(private UserRepositoryInterface $repository) {}

public function __invoke(UserInfo $command): void
{
$user = new User(
$command->getUser()->getId(),
$command->getUser()->getFirstName(),
$command->getUser()-> getSurname(),
$command->getUser()->getEmail()
);

$this->repository->save($user);
}
}
1 change: 0 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ services:
context: .
dockerfile: Dockerfile
target: app
image: ghcr.io/oskarbarcz/symfony-project-bootstrap:app-${VERSION:-3.0.0}
environment:
APP_ENV: "dev"
APP_SECRET: "a9806d99cd5c1503d8af30c963c9411f"
Expand Down

0 comments on commit 776b531

Please sign in to comment.