/** * Handle an event. * * @param EventInterface $event * * @return void */ public function handle(EventInterface $event) { if (!$event instanceof SerializableEvent) { throw new \InvalidArgumentException(sprintf('Cannot serialize %s event.', $event->getName())); } $this->publisher->publish(json_encode($event->toArray()), $event->getName()); }
/** * @param object $command * @param callable $next * * @return mixed */ public function execute($command, callable $next) { if (!$command instanceof NamedCommand) { throw new \InvalidArgumentException('Command must be a NamedCommand'); } $this->queuePublisher->publish($this->serializer->serialize($command), $command->getCommandName()); }
/** * {@inheritdoc} */ public function commit() { foreach ($this->messages as $message) { $this->publisher->publish($message['data'], $message['routingKey']); } $this->messages = []; $this->running = false; }
function it_should_not_publish_message_when_rollbacking(QueuePublisher $publisher) { $this->beginTransaction(); $publisher->publish('', '')->shouldNotBeCalled(); $this->publish('', ''); $this->rollback(); }
/** * Publishes the events from the domain event stream to the listeners. * * @param DomainEventStreamInterface $domainMessages * @throws \Exception */ public function publish(DomainEventStreamInterface $domainMessages) { $this->queue[] = $domainMessages; if (!$this->isPublishing) { $this->isPublishing = true; try { parent::publish($domainMessages); while ($domainMessageStream = array_shift($this->queue)) { $serializedDomainMessages = $this->serializer->serialize($domainMessages); $this->queuePublisher->publish($serializedDomainMessages); } } catch (\Exception $e) { throw $e; } finally { $this->isPublishing = false; } } }
/** * Handle an event. * * @param EventInterface $event * * @return void */ public function handle(EventInterface $event) { $this->publisher->publish($this->serializer->serialize($event), $event->getName()); }