Closed matiazar closed 1 year ago
I have reused previous commit without horizon and now is working.... I dont know what was...
Again me... now when I run php artisan queue:work --once
its entering to the payload() function... but thats all... its not executing fire or handle function. what can be wrong?
working!
Like it is a cli command I didnt notice to check laravel log.... the problem was I didnt update RABBITMQ_WORKER=horizon to RABBITMQ_WORKER=default after removing horizon
thanks!
@vyuldashev can you check this?
I have made a class that check if message is from laravel or not so it select what Job "controller" use only with overwritting the payload function
<?php
namespace App\Jobs;
use Illuminate\Support\Str;
use Illuminate\Queue\Jobs\JobName;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob;
use function PHPUnit\Framework\isJson;
class ProcessMessageJob extends RabbitMQJob
{
private function isLaravelJob($data){
if (isset($data['data']) && isset($data['data']['commandName']) && isset($data['data']['command'])) return true;
return false;
}
private function isJson($string)
{
json_decode($string);
return json_last_error() === JSON_ERROR_NONE;
}
/**
* Get the decoded body of the job.
*
* @return array
*/
public function payload(): array
{
$data = $this->getRawBody();
if ($this->isJson($data)) $data = json_decode($data, true);
if ($this->isLaravelJob($data)) return $data;
return [
'uuid' => Str::uuid(),
'displayName' => HandleMessage::class,
'job' => 'Illuminate\\Queue\\CallQueuedHandler@call',
'data' => [
'commandName' => HandleMessage::class,
'command' => serialize(new HandleMessage($data)),
],
'id' => Str::uuid(),
];
}
}
Im dispatching some job from Laravel to RabbitMQ but when I execute
php artisan rabbitmq:consume --once or php artisan queue:work --once
the worker is using default job from where it was dispatched... and not the one I created
this is my rabbitmq.php config file
Expected behavior
to message be captured by App\Jobs\RabbitMQ\RabbitMQJob::class
please. help. thanks!!