Last active
May 18, 2016 13:23
-
-
Save webdevilopers/f3519ad7a1df19ac38dc3649ff54bb79 to your computer and use it in GitHub Desktop.
How to handle events from recorder with SimpleBus in Symfony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AddDefectHandler | |
implements MessageHandler | |
{ | |
/** | |
* @var RecordsMessages $eventRecorder | |
*/ | |
private $eventRecorder; | |
public function handle(Message $command) | |
{ | |
$this->defectRepository->save($defect); | |
$defectAdded = new DefectAdded(new DefectTypeId($defect->id())); | |
$this->eventRecorder->record($defectAdded); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DefectController extends Controller | |
{ | |
public function addDefectAction(Request $request, Contract $order) | |
{ | |
$command = AddOrderDefectCommand::fromOrder($order); | |
$handler->handle($command); | |
$defectAdded = new DefectAdded(new DefectTypeId(1)); | |
$eventBus = $this->get('event_bus'); | |
$eventBus->handle($defectAdded); // works fine | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" ?> | |
<container xmlns="http://symfony.com/schema/dic/services" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |
<services> | |
<service id="qms.subscriber.defect_added" | |
class="Acme\Application\Services\DefectAddedSubscriber"> | |
<tag name="event_subscriber" subscribes_to="Acme\DomainModel\Defect\DefectAdded" /> | |
</service> | |
</services> | |
</container> |
Do you have a working event_subscriber
with the current @SimpleBus version @josecelano ?
Does your event_subscriber
fire automatically @Axxon?
@webdevilopers Hello, into my example that you quoted, after time between write and reading, i think i made a mistake, the end message should be "i'm a asynchronous command"!, so good question. Commands are dealed asynchronously then related events are synchronous ... So i will check that this week-end.
Thanks for the feedback @Axxon. Looking forward to your answer!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Came from:
As far as I understand the Events should be called after the Command was handled without having to call the handle() method on the
EventBus
manually. Just like with Symfony Event dispatcher.Unfortunately this does not seem to fire automatically.