src/Dispatcher.php
public function handle(): void
    {
        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);
        }
    }
public function handle(): void
    {
        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);
        }
    }
public function handle ( ) : void { 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 ) ; } }
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
Basic method for background job to star listening .