public function listen()
{
if ($this->closed) {
throw new BadMethodCallException('This listener object is closed and cannot receive any more messages.');
}
while ($envelope = $this->queue->get()) {
$storedEvent = $this->serializer->deserialize($envelope->getBody(), 'Ddd\\Domain\\Event\\StoredEvent', 'json');
if ($this->listensTo($storedEvent->typeName())) {
$this->handle(json_decode($storedEvent->eventBody()));
}
if ($this->stop) {
return;
}
}
}