Ejemplo n.º 1
0
 /**
  * Basic method for background job to star listening.
  *
  * This method hook to driver wait() method and start listening events.
  * Method is blocking, so when you call it all processing will stop.
  * WARNING! Don't use it on web server calls. Run it only with cli.
  *
  * @return void
  */
 public function handle()
 {
     try {
         $this->driver->wait(function (MessageInterface $message) {
             $this->log(LogLevel::INFO, "Start handle message #{$message->getId()} ({$message->getType()})", $this->messageLoggerContext($message));
             $result = $this->dispatch($message);
             if ($this->restart && $this->restart->shouldRestart($this->startTime)) {
                 throw new RestartException('Restart');
             }
             return $result;
         });
     } catch (RestartException $e) {
         $this->log(LogLevel::NOTICE, 'Existing hermes dispatcher - restart');
     } catch (Exception $exception) {
         Debugger::log($exception, Debugger::EXCEPTION);
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function emit(MessageInterface $message)
 {
     $this->driver->send($message);
     $this->log(LogLevel::INFO, "Dispatcher send message #{$message->getId()} to driver " . get_class($this->driver), $this->messageLoggerContext($message));
     return $this;
 }