I created an event and a listener for it in my project. The listener is queued (by implementing _ShouldQueue_ interface). When I run artisan command, it calls my custom service, where the event is fired. I mapped the event with its listener in _EventServiceProvider_, but the listener is never reached. Instead, the exception is thrown:
[ReflectionException]
Class does not exist
Yes, mentioned class name is ' ' (sick!).
if (count($createdClientsData) > 0) {
event(new ExternalClientsCreated($createdClientsData));
}
<?php
namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ExternalClientsCreated extends Event
{
use SerializesModels;
public $clientsData;
public function __construct($clientsData = [])
{
$this->clientsData = $clientsData;
}
}
protected $listen = [
ExternalClientsCreated::class => [
ExternalClientsCreation::class,
],
];
<?php
namespace App\Listeners;
use App\Events\ExternalClientsCreated;
use App\Library\Services\ClientService;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class ExternalClientsCreation implements ShouldQueue
{
use InteractsWithQueue;
protected $clientService;
public function __construct(ClientService $clientService)
{
$this->clientService = $clientService;
}
public function handle(ExternalClientsCreated $event)
{
$this->clientService->createClients($event->clientsData);
}
}
[2016-10-13 17:06:13] local.ERROR: ReflectionException: Class does not exist in /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Container/Container.php:734
Stack trace:
#0 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Container/Container.php(734): ReflectionClass->__construct('')
#1 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('', Array)
#2 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('', Array)
#3 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(154): Illuminate\Foundation\Application->make('')
#4 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(210): Illuminate\Queue\Jobs\Job->resolve('')
#5 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php(153): Illuminate\Queue\Jobs\Job->failed()
#6 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php(42): Illuminate\Queue\SyncQueue->handleFailedJob(Object(Illuminate\Queue\Jobs\SyncJob))
#7 [internal function]: Illuminate\Queue\SyncQueue->push('Illuminate\\Even...', Array)
#8 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php(267): call_user_func_array(Array, Array)
#9 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(416): Illuminate\Queue\QueueManager->__call('push', Array)
#10 [internal function]: Illuminate\Events\Dispatcher->Illuminate\Events\{closure}(Object(App\Events\ExternalClientsCreated))
#11 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(347): call_user_func_array(Object(Closure), Array)
#12 [internal function]: Illuminate\Events\Dispatcher->Illuminate\Events\{closure}(Object(App\Events\ExternalClientsCreated))
#13 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(221): call_user_func_array(Object(Closure), Array)
#14 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(419): Illuminate\Events\Dispatcher->fire('App\\Events\\Exte...', Array, false)
#15 /home/vagrant/Code/medhub/app/Library/Services/FirebirdService.php(52): event(Object(App\Events\ExternalClientsCreated))
#16 /home/vagrant/Code/medhub/app/Console/Commands/LoadClients.php(16): App\Library\Services\FirebirdService->loadClients()
#17 [internal function]: App\Console\Commands\LoadClients->handle(Object(App\Library\Services\FirebirdService))
#18 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#19 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#20 /home/vagrant/Code/medhub/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /home/vagrant/Code/medhub/vendor/symfony/console/Application.php(794): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /home/vagrant/Code/medhub/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(App\Console\Commands\LoadClients), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /home/vagrant/Code/medhub/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /home/vagrant/Code/medhub/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /home/vagrant/Code/medhub/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 {main}
Thanks in advance!
You need to digg more into that, this scenario works fine for all the apps I ever built so I'd say it's something wrong with your code.
Just gonna guess real fast that the ExternalClientsCreated namespace is at the top of your EventServiceProvider? And there is no typo? If your class is there usually the problem is it is looking at the wrong namespace.
Same goes for any class where you are firing this event. Check to see that you have every namespace included correctly.
@miscbits
Yes, namespaces are fine. BTW, I'm using PHPStorm IDE, so if there were any typos or missing namespaces I would probably notice...
I also think that 'Class does not exist' message would include the actual class name in that case.
Looking at the stack trace I don't think the queue driver used was sync, can you confirm @tonystatic ?
@tonystatic What do you path in clientsData? I suspect that the job payload failed to create.
Just noticed your issue is addressing 5.2, in 5.3 we throw an exception if the payload building fails, please upgrade to 5.3 so that you get more details about why the job is failing.
@themsaid
Yes, the queue driver is definitely sync.
$clientsData is a multidimensional array of text data (rather big, about 9000 of small arrays in this particular case), I can dd it normally before firing event.
So, upgrading is the only way to reveal the problem? Ok, I may try it later.
Thanks for the answer!
I receive this error when using mssql database, while it's working fine when using mysql database.
edit: nevermind. seems like the payload get truncated in mssql, i've to choose different datatype other than nvarchar(max)