PHP code example of semnickolas / laravel-queue-rabbitmq
1. Go to this page and download the library: Download semnickolas/laravel-queue-rabbitmq library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
semnickolas / laravel-queue-rabbitmq example snippets
'connections' => [
// ...
'rabbitmq' => [
// ...
/* Set to "horizon" if you wish to use Laravel Horizon. */
'worker' => env('RABBITMQ_WORKER', 'default'),
],
// ...
],
namespace App\Queue\Jobs;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob as BaseJob;
class RabbitMQJob extends BaseJob
{
/**
* Fire the job.
*
* @return void
*/
public function fire()
{
$payload = $this->payload();
$class = WhatheverClassNameToExecute::class;
$method = 'handle';
($this->instance = $this->resolve($class))->{$method}($this, $payload);
$this->delete();
}
}
namespace App\Queue\Jobs;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob as BaseJob;
class RabbitMQJob extends BaseJob
{
/**
* Get the decoded body of the job.
*
* @return array
*/
public function payload()
{
return [
'job' => 'WhatheverFullyQualifiedClassNameToExecute@handle',
'data' => json_decode($this->getRawBody(), true)
];
}
}
namespace App\Queue\Jobs;
use Illuminate\Support\Facades\Log;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob as BaseJob;
class RabbitMQJob extends BaseJob
{
public function fire()
{
$anyMessage = $this->getRawBody();
Log::info($anyMessage);
$this->delete();
}
public function getName()
{
return '';
}
}
'connections' => [
// ...
'rabbitmq' => [
// ...
/* Set to a class if you wish to use your own. */
'worker' => \App\Queue\RabbitMQQueue::class,
],
// ...
],
namespace App\Queue;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue as BaseRabbitMQQueue;
class RabbitMQQueue extends BaseRabbitMQQueue
{
// ...
}