/**
  * @param ActionEvent $actionEvent
  */
 public function onEventStoreCommitPost(ActionEvent $actionEvent)
 {
     $this->queuedActionEvents[] = $actionEvent;
     if (!$this->inConfirmSelectMode) {
         $this->inConfirmSelectMode = true;
         while ($actionEvent = array_shift($this->queuedActionEvents)) {
             $fallback = new \ArrayIterator();
             $recordedEvents = $actionEvent->getParam('recordedEvents', $fallback);
             if ($fallback !== $recordedEvents) {
                 $this->producer->confirmSelect();
             }
             $countRecordedEvents = 0;
             foreach ($recordedEvents as $recordedEvent) {
                 $this->eventBus->dispatch($recordedEvent);
                 $countRecordedEvents++;
             }
             if ($fallback !== $recordedEvents) {
                 $this->producer->setConfirmCallback(function (int $deliveryTag, bool $multiple) use($countRecordedEvents) {
                     return $deliveryTag !== $countRecordedEvents;
                 }, function (int $deliveryTag, bool $multiple, bool $requeue) use(&$result) {
                     throw new RuntimeException('Could not publish all events');
                 });
                 $this->producer->waitForConfirm($this->timeout);
             }
         }
         $this->inConfirmSelectMode = false;
     }
 }
 /**
  * @param Message $message
  * @param Deferred|null $deferred
  * @throws RuntimeException If a $deferred is passed but producer can not handle it
  * @return void
  */
 public function __invoke(Message $message, Deferred $deferred = null)
 {
     if (null !== $deferred) {
         throw new RuntimeException(__CLASS__ . ' cannot handle query messages which require future responses.');
     }
     $data = $this->arrayFromMessage($message);
     $attributes = ['app_id' => $this->appId, 'timestamp' => $message->createdAt()->getTimestamp(), 'type' => $message->messageName()];
     $this->producer->publish($data, $message->messageName(), Constants::AMQP_NOPARAM, $attributes);
 }
 /**
  * @param Message $message
  * @param Deferred|null $deferred
  * @return void
  * @throws RuntimeException
  */
 public function __invoke(Message $message, Deferred $deferred = null)
 {
     if (!$message instanceof DelayedMessage) {
         throw new RuntimeException(sprintf('Message is not a delayed message (instance of %s)', DelayedMessage::class));
     }
     if (null !== $deferred) {
         throw new RuntimeException(__CLASS__ . ' cannot handle query messages which require future responses.');
     }
     $data = $this->arrayFromMessage($message);
     $attributes = ['headers' => ['x-delay' => $message->delay()], 'app_id' => $this->appId, 'timestamp' => $message->createdAt()->getTimestamp(), 'type' => $message->messageName()];
     $this->producer->publish($data, $message->messageName(), Constants::AMQP_NOPARAM, $attributes);
 }
 /**
  * @param ActionEvent $actionEvent
  */
 public function onEventStoreCommitPost(ActionEvent $actionEvent)
 {
     $this->queuedActionEvents[] = $actionEvent;
     if (!$this->inTransaction) {
         $this->inTransaction = true;
         while ($actionEvent = array_shift($this->queuedActionEvents)) {
             $fallback = new \ArrayIterator();
             $recordedEvents = $actionEvent->getParam('recordedEvents', $fallback);
             if ($fallback !== $recordedEvents) {
                 $this->producer->startTransaction();
             }
             foreach ($recordedEvents as $recordedEvent) {
                 $this->eventBus->dispatch($recordedEvent);
             }
             if ($fallback !== $recordedEvents) {
                 $this->producer->commitTransaction();
             }
         }
         $this->inTransaction = false;
     }
 }