/** * A callback function to which the consumed message will be passed. * All messages are dispatched as events. * Catched errors are dispatched as well using special event "kemer.error". * NotConsumedException is threw - when dispatched message is not marked * as `consumed` either by acknowledging or rejecting * * @param AMQPEnvelope $envelope * @param AMQPQueue $queue * @return void * @throws Exceptions\ConsumerException * @throws Exceptions\NotConsumedException */ public function __invoke(\AMQPEnvelope $envelope, \AMQPQueue $queue) { $event = new ConsumeEvent($envelope, $queue); try { $this->dispatcher->dispatch($event->getRoutingKey(), $event); } catch (\Exception $e) { $this->dispatcher->dispatch(static::ERROR_EVENT, new SymfonyEvent($event, ["error" => $e])); if (!$event->isConsumed()) { throw new Exceptions\ConsumerException($event, $e); } } if (!$event->isConsumed()) { throw new Exceptions\NotConsumedException($event); } }
/** * Dispatches an event to all registered listeners. * * @param EventInterface $event The event to pass to the event handlers/listeners. * * @return EventInterface The event after being passed through all listeners. * * @since __DEPLOY_VERSION__ */ public function dispatch(EventInterface $event) { return $this->dispatcher->dispatch($event); }
/** * Dispatches an event to all registered listeners. * * @param string $name The name of the event to dispatch. * @param EventInterface $event The event to pass to the event handlers/listeners. * * @return EventInterface The event after being passed through all listeners. * * @since __DEPLOY_VERSION__ */ public function dispatch($name, EventInterface $event = null) { return $this->dispatcher->dispatch($name, $event); }