diff --git a/README.md b/README.md index 7e740cb7..46203859 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ Starting with 8.0, this package supports [Laravel Horizon](http://horizon.larave For Lumen usage the service provider should be registered manually as follow in `bootstrap/app.php`: ```php -$app->register(VladimirYuldashev\LaravelQueueRabbitMQ\LaravelQueueRabbitMQServiceProvider::class); +$app->register(Yuriksensej\LaravelQueueRabbitMQ\LaravelQueueRabbitMQServiceProvider::class); ``` diff --git a/composer.json b/composer.json index eec27d09..85246f8c 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { - "name": "vladimir-yuldashev/laravel-queue-rabbitmq", + "name": "yuriksensej/laravel-queue-rabbitmq", "description": "RabbitMQ driver for Laravel Queue. Supports Laravel Horizon", "license": "MIT", "authors": [ { - "name": "Vladimir Yuldashev", - "email": "misterio92@gmail.com" + "name": "Yurii Minchenko", + "email": "yuraminchenko@gmail.com" } ], "require": { @@ -25,12 +25,12 @@ }, "autoload": { "psr-4": { - "VladimirYuldashev\\LaravelQueueRabbitMQ\\": "src/" + "Yuriksensej\\LaravelQueueRabbitMQ\\": "src/" } }, "autoload-dev": { "psr-4": { - "VladimirYuldashev\\LaravelQueueRabbitMQ\\Tests\\": "tests/" + "Yuriksensej\\LaravelQueueRabbitMQ\\Tests\\": "tests/" } }, "extra": { @@ -39,7 +39,7 @@ }, "laravel": { "providers": [ - "VladimirYuldashev\\LaravelQueueRabbitMQ\\LaravelQueueRabbitMQServiceProvider" + "Yuriksensej\\LaravelQueueRabbitMQ\\LaravelQueueRabbitMQServiceProvider" ] } }, diff --git a/src/Horizon/Listeners/RabbitMQFailedEvent.php b/src/Horizon/Listeners/RabbitMQFailedEvent.php index e13445f4..bb05b139 100644 --- a/src/Horizon/Listeners/RabbitMQFailedEvent.php +++ b/src/Horizon/Listeners/RabbitMQFailedEvent.php @@ -1,11 +1,11 @@ declareEverything($queueName); $consumer = $this->context->createConsumer($queue); - + $job = $this->getJobClass(); if ($message = $consumer->receiveNoWait()) { - return new RabbitMQJob($this->container, $this, $consumer, $message); + return new $job($this->container, $this, $consumer, $message); } } catch (\Throwable $exception) { $this->reportConnectionError('pop', $exception); @@ -300,4 +301,19 @@ protected function reportConnectionError($action, \Throwable $e) // Sleep so that we don't flood the log file sleep($this->sleepOnError); } + + /** + * Gets the Job class from config or returns the default job class + * when the job class does not extend the default job class an exception is thrown + * + * @return array|\ArrayAccess|mixed + * @throws \Throwable + */ + public function getJobClass() + { + $job = Arr::get($this->queueOptions, 'job', RabbitMQJob::class); + throw_if(! is_a($job, RabbitMQJob::class, true), Exception::class, sprintf('Class %s must extend: %s', $job, RabbitMQJob::class)); + + return $job; + } } diff --git a/tests/Functional/SendAndReceiveDelayedMessageTest.php b/tests/Functional/SendAndReceiveDelayedMessageTest.php index 1a6ae946..b4c13436 100644 --- a/tests/Functional/SendAndReceiveDelayedMessageTest.php +++ b/tests/Functional/SendAndReceiveDelayedMessageTest.php @@ -1,15 +1,15 @@