Skip to content

Commit

Permalink
Improve bc comm.
Browse files Browse the repository at this point in the history
  • Loading branch information
zerai committed Mar 1, 2024
1 parent ceb28d5 commit 1bf00ff
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);

/*
* This file is part of the medicalmundi/marketplace-accounts
*
* @copyright (c) 2023 MedicalMundi
*
* This software consists of voluntary contributions made by many individuals
* {@link https://github.com/medicalmundi/marketplace-accounts/graphs/contributors developer} and is licensed under the MIT license.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* @license https://github.com/MedicalMundi/marketplace-accounts/blob/main/LICENSE MIT
*/

namespace IdentityAccess\Infrastructure\Ecotone;

use Ecotone\Dbal\Configuration\DbalConfiguration;
use Ecotone\Messaging\Attribute\ServiceContext;

class IdentityAccessDbalConfiguration
{
// #[ServiceContext]
// public function getDbalConfiguration(): DbalConfiguration
// {
// return DbalConfiguration::createWithDefaults()
// ->withDocumentStore(initializeDatabaseTable: true, enableDocumentStoreAggregateRepository: true);
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

/*
* This file is part of the medicalmundi/marketplace-accounts
*
* @copyright (c) 2023 MedicalMundi
*
* This software consists of voluntary contributions made by many individuals
* {@link https://github.com/medicalmundi/marketplace-accounts/graphs/contributors developer} and is licensed under the MIT license.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* @license https://github.com/MedicalMundi/marketplace-accounts/blob/main/LICENSE MIT
*/

namespace IdentityAccess\Infrastructure\Ecotone;

use Ecotone\Dbal\DbalBackedMessageChannelBuilder;
use Ecotone\Messaging\Attribute\ServiceContext;

class IdentityAccessMessagingConfiguration
{
#[ServiceContext]
public function identityAccessDistributedChannel(): DbalBackedMessageChannelBuilder
{
return DbalBackedMessageChannelBuilder::create("iam_distributed");
}
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* @license https://github.com/MedicalMundi/marketplace-accounts/blob/main/LICENSE MIT
*/

namespace Notifier\AdapterForAntiCorruptionLayer\MessageFromIdentityAccess;
namespace Notifier\AdapterForAntiCorruptionLayer\DistributedMessage;

use Ecotone\Messaging\Attribute\Asynchronous;
use Ecotone\Messaging\Attribute\Parameter\Headers;
use Ecotone\Messaging\Attribute\Parameter\Payload;
use Ecotone\Modelling\Attribute\EventHandler;
Expand All @@ -24,7 +25,8 @@
use Psr\Log\LoggerInterface;
use Ramsey\Uuid\Uuid;

class IncomingMessageProcessor
#[Asynchronous("notifier_distributed")]
class MessageProcessor
{
public function __construct(
private readonly CommandBus $commandBus,
Expand All @@ -33,19 +35,15 @@ public function __construct(
) {
}

#[EventHandler(listenTo: 'iam.new-user-registration-was-accepted')]
#[EventHandler(listenTo: 'iam.*', endpointId: "notifier_distributed_message_processor")]
public function handle(#[payload] array $event, #[headers] array $headers): void
{
$isAlreadyProcessed = $this->cacheItemPool->getItem('already-processed-message.' . (string) $headers['id']);
if (! $isAlreadyProcessed->isHit()) {
// ... item does not exist in the cache
$this->logger->info('---------------------- precess external message ----------------------');
//TODO:
// create new UserRecipient
// call domain command createUserRecipient
// or
// create own projections from external events.

// check for unique Id and email before creation
$command = new CreateUserRecipient();
$command->id = Uuid::fromString((string) $event['userId']);
$command->email = (string) $event['userEmail'];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);

/*
* This file is part of the medicalmundi/marketplace-accounts
*
* @copyright (c) 2023 MedicalMundi
*
* This software consists of voluntary contributions made by many individuals
* {@link https://github.com/medicalmundi/marketplace-accounts/graphs/contributors developer} and is licensed under the MIT license.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* @license https://github.com/MedicalMundi/marketplace-accounts/blob/main/LICENSE MIT
*/

namespace Notifier\AdapterForAntiCorruptionLayer\DistributedMessage;

use Ecotone\Messaging\Attribute\Asynchronous;
use Ecotone\Modelling\CommandBus;
use Psr\Log\LoggerInterface;

#[Asynchronous("notifier_distributed")]
class MessagePublisher
{
public function __construct(
private readonly CommandBus $commandBus,
private readonly LoggerInterface $logger,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
class NotifierMessagingConfiguration
{
#[ServiceContext]
public function orderChannel(): DbalBackedMessageChannelBuilder
public function notifierDistributedChannel(): DbalBackedMessageChannelBuilder
{
return DbalBackedMessageChannelBuilder::create("notifier");
return DbalBackedMessageChannelBuilder::create("notifier_distributed");
}
}
23 changes: 23 additions & 0 deletions config/packages/prooph_pdo_event_store.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,26 @@ services:

app.event_store.postgres.persistence_strategy:
class: Prooph\EventStore\Pdo\PersistenceStrategy\PostgresSingleStreamStrategy

########



notifier.event_store.default:
class: Prooph\EventStore\Pdo\MariaDbEventStore
arguments:
#TODO: ectone message factory?
- '@prooph_event_store.message_factory'
- '@notifier.event_store.pdo_connection.mariadb'
- '@notifier.event_store.postgres.persistence_strategy'

notifier.event_store.pdo_connection.mariadb:
class: \PDO
arguments:
- '%env(DATABASE_URL)%'
#- '%env(EVENT_STORE_USER)%'
#- '%env(EVENT_STORE_PASSWORD)%'

notifier.event_store.postgres.persistence_strategy:
class: Prooph\EventStore\Pdo\PersistenceStrategy\MariaDbSingleStreamStrategy

0 comments on commit 1bf00ff

Please sign in to comment.