/**
  * @param ActionEvent $event
  */
 public function onDispatchInitialize(ActionEvent $event)
 {
     $bus = $event->getTarget();
     if ($bus instanceof EventBus) {
         $listeners = $event->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS, []);
         $listeners[] = $this->messageProducer;
         $event->setParam(EventBus::EVENT_PARAM_EVENT_LISTENERS, $listeners);
     } else {
         $event->setParam(MessageBus::EVENT_PARAM_MESSAGE_HANDLER, $this->messageProducer);
     }
 }
 /**
  * @param ActionEvent $actionEvent
  */
 public function onRouteMessage(ActionEvent $actionEvent)
 {
     $messageName = (string) $actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE_NAME);
     if (empty($messageName)) {
         return;
     }
     $message = $actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE);
     //if the message is marked with AsyncMessage, but had not yet been sent via async then sent to async producer
     if ($message instanceof AsyncMessage && !(isset($message->metadata()['handled-async']) && $message->metadata()['handled-async'] === true)) {
         //apply meta data, this is need to we can identify that the message has already been send via the async producer
         $message = $message->withAddedMetadata('handled-async', true);
         // update ActionEvent
         $actionEvent->setParam(MessageBus::EVENT_PARAM_MESSAGE, $message);
         if ($actionEvent->getTarget() instanceof CommandBus || $actionEvent->getTarget() instanceof QueryBus) {
             $actionEvent->setParam(MessageBus::EVENT_PARAM_MESSAGE_HANDLER, $this->asyncMessageProducer);
         } else {
             //Target is an event bus so we set message producer as the only listener of the message
             $actionEvent->setParam(EventBus::EVENT_PARAM_EVENT_LISTENERS, [$this->asyncMessageProducer]);
         }
         return;
     }
     // pass ActionEvent to decorated router
     return $this->router->onRouteMessage($actionEvent);
 }
Esempio n. 3
0
 /**
  * @param ActionEvent $actionEvent
  */
 public function onRoute(ActionEvent $actionEvent)
 {
     if ($actionEvent->getTarget() instanceof CommandBus || $actionEvent->getTarget() instanceof QueryBus) {
         $this->onRouteToSingleHandler($actionEvent);
     } else {
         $this->onRouteEvent($actionEvent);
     }
 }