Skip to content

Commit

Permalink
separate event publishing command bus
Browse files Browse the repository at this point in the history
  • Loading branch information
dgafka committed Jul 31, 2019
1 parent 347c6a6 commit cf091c6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/DomainModel/CommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ interface CommandBus
* @return mixed
*
* @Gateway(requestChannel=CommandBus::CHANNEL_NAME_BY_OBJECT)
* @LazyEventPublishing()
*/
public function send($command);

Expand All @@ -48,7 +47,6 @@ public function send($command);
* @Headers(parameterName="metadata")
* }
* )
* @LazyEventPublishing()
*/
public function sendWithMetadata($command, array $metadata);

Expand All @@ -66,7 +64,6 @@ public function sendWithMetadata($command, array $metadata);
* @Payload(parameterName="commandData")
* }
* )
* @LazyEventPublishing()
*/
public function convertAndSend(string $name, string $dataMediaType, $commandData);

Expand All @@ -87,7 +84,6 @@ public function convertAndSend(string $name, string $dataMediaType, $commandData
* @Payload(parameterName="commandData")
* }
* )
* @LazyEventPublishing()
*/
public function convertAndSendWithMetadata(string $name, string $dataMediaType, $commandData, array $metadata);
}
91 changes: 91 additions & 0 deletions src/DomainModel/CommandBusWithEventPublishing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php


namespace SimplyCodedSoftware\DomainModel;

use SimplyCodedSoftware\Messaging\Annotation\MessageEndpoint;
use SimplyCodedSoftware\DomainModel\LazyEventBus\LazyEventPublishing;
use SimplyCodedSoftware\Messaging\Annotation\Gateway;
use SimplyCodedSoftware\Messaging\Annotation\Parameter\Header;
use SimplyCodedSoftware\Messaging\Annotation\Parameter\Headers;
use SimplyCodedSoftware\Messaging\Annotation\Parameter\Payload;
use SimplyCodedSoftware\Messaging\MessageHeaders;

/**
* Interface CommandBusWithEventPublishing
* @package SimplyCodedSoftware\DomainModel
* @author Dariusz Gafka <[email protected]>
* @MessageEndpoint()
*/
interface CommandBusWithEventPublishing extends CommandBus
{
/**
* Entrypoint for commands, when you access to instance of the command
*
* @param object $command instance of command
*
* @return mixed
*
* @Gateway(requestChannel=CommandBus::CHANNEL_NAME_BY_OBJECT)
* @LazyEventPublishing()
*/
public function send($command);

/**
* Entrypoint for commands, when you access to instance of the command
*
* @param object $command instance of command
* @param array $metadata
*
* @return mixed
*
* @Gateway(
* requestChannel=CommandBus::CHANNEL_NAME_BY_OBJECT,
* parameterConverters={
* @Payload(parameterName="command"),
* @Headers(parameterName="metadata")
* }
* )
* @LazyEventPublishing()
*/
public function sendWithMetadata($command, array $metadata);

/**
* @param string $name
* @param string $dataMediaType
* @param mixed $commandData
*
* @return mixed
* @Gateway(
* requestChannel=CommandBus::CHANNEL_NAME_BY_NAME,
* parameterConverters={
* @Header(parameterName="name", headerName=CommandBus::CHANNEL_NAME_BY_NAME),
* @Header(parameterName="dataMediaType", headerName=MessageHeaders::CONTENT_TYPE),
* @Payload(parameterName="commandData")
* }
* )
* @LazyEventPublishing()
*/
public function convertAndSend(string $name, string $dataMediaType, $commandData);

/**
* @param string $name
* @param string $dataMediaType
* @param mixed $commandData
* @param array $metadata
*
* @return mixed
*
* @Gateway(
* requestChannel=CommandBus::CHANNEL_NAME_BY_NAME,
* parameterConverters={
* @Headers(parameterName="metadata"),
* @Header(parameterName="name", headerName=CommandBus::CHANNEL_NAME_BY_NAME),
* @Header(parameterName="dataMediaType", headerName=MessageHeaders::CONTENT_TYPE),
* @Payload(parameterName="commandData")
* }
* )
* @LazyEventPublishing()
*/
public function convertAndSendWithMetadata(string $name, string $dataMediaType, $commandData, array $metadata);
}
1 change: 1 addition & 0 deletions tests/DomainModel/Behat/features/modelling.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Feature: activating as aggregate order entity
And shipping address should be "London 12th street" for order with id 1
When I change order with id of 1 the shipping address to "London 13th street"
Then shipping address should be "London 13th street" for order with id 1
And there should notification 2 awaiting notification
Then there should be 20 products for order with id 1 retrieved from "get_order_amount_channel"

Scenario: I reorder product, then the amount should be increased
Expand Down
2 changes: 2 additions & 0 deletions tests/DomainModel/Fixture/CommandHandler/Aggregate/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public function changeShippingAddress(ChangeShippingAddressCommand $command) : v
{
$this->shippingAddress = $command->getShippingAddress();
$this->increaseAggregateVersion();

$this->record(new Notification());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\Common\Annotations\AnnotationException;
use PHPUnit\Framework\Assert;
use SimplyCodedSoftware\DomainModel\CommandBus;
use SimplyCodedSoftware\DomainModel\CommandBusWithEventPublishing;
use SimplyCodedSoftware\DomainModel\EventBus;
use SimplyCodedSoftware\DomainModel\LazyEventBus\LazyEventBus;
use SimplyCodedSoftware\DomainModel\QueryBus;
Expand Down Expand Up @@ -176,7 +177,7 @@ public function calendarShouldContainEventWithAppointmentId(int $appointmentId)
*/
public static function getCommandBus(): CommandBus
{
return self::$messagingSystem->getGatewayByName(CommandBus::class);
return self::$messagingSystem->getGatewayByName(CommandBusWithEventPublishing::class);
}

/**
Expand Down

0 comments on commit cf091c6

Please sign in to comment.