/** * Run receiver instance * * @throws \RuntimeException * @throws InvalidMessageException */ public function runReceiver() { if (null === $this->adapter) { throw new \RuntimeException('Can\'t run receiver. Adapter not found.'); } if (null === $this->notification) { throw new \RuntimeException('Can\'t run receiver. Notification not found.'); } while ($this->adapter->isNextReceive()) { if ($message = $this->adapter->getMessage()) { if (!$message instanceof MessageInterface) { throw new InvalidMessageException(sprintf('Message must be instance MessageInterface, "%s" given.', is_object($message) ? get_class($message) : gettype($message))); } try { $this->notification->send($message); } catch (SendException $e) { if ($this->notificationErrorHandler) { call_user_func($this->notificationErrorHandler, $e); } } } } }