Laravel 12 Eylül 2021

laravel rabbitmq

#laravel
composer require vladimir-yuldashev/laravel-queue-rabbitmq
docker run -d --hostname my-rabbit --name rabbitmq -p 8080:15672 -p 5672:5672 rabbitmq:3-managementqueue.php
'rabbitmq' = [    'driver' = 'rabbitmq',    'queue' = env('RABBITMQ_QUEUE', 'statusOfBill'),    'connection' = PhpAmqpLib\\Connection\\AMQPLazyConnection::class,    'hosts' = [        [            'host' = env('RABBITMQ_HOST', '127.0.0.1'),            'port' = env('RABBITMQ_PORT', 5672),            'user' = env('RABBITMQ_USER', 'guest'),            'password' = env('RABBITMQ_PASSWORD', 'guest'),            'vhost' = env('RABBITMQ_VHOST', '/'),        ],    ],    'options' = [        'ssl_options' = [            'cafile' = env('RABBITMQ_SSL_CAFILE', null),            'local_cert' = env('RABBITMQ_SSL_LOCALCERT', null),            'local_key' = env('RABBITMQ_SSL_LOCALKEY', null),            'verify_peer' = env('RABBITMQ_SSL_VERIFY_PEER', true),            'passphrase' = env('RABBITMQ_SSL_PASSPHRASE', null),        ],        'queue' = [            'job' = VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob::class,        ],    ],    /*     * Set to "horizon" if you wish to use Laravel Horizon.     */    'worker' = env('RABBITMQ_WORKER', 'default'),],
 .env 
QUEUE_CONNECTION=rabbitmq
 publisherphp artisan make:job TestJob
class TestJob implements ShouldQueue{    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;    private $data;    /**     * Create a new job instance.     *     * @return void     */    public function __construct($data)    {        $this-data = $data;    }    /**     * Execute the job.     *     * @return void     */    public function handle()    {    }}
php artisan make:command FireEvent
class FireEvent extends Command{    /**     * The name and signature of the console command.     *     * @var string     */    protected $signature = 'fire';    public function handle()    {        TestJob::dispatch(MemorizedPage::find(1)-toArray());    }}
    Consumerphp artisan make:job TestJob
class TestJob implements ShouldQueue{    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;    private $data;    /**     * Create a new job instance.     *     * @return void     */    public function __construct($data)    {        $this-data = $data;    }    /**     * Execute the job.     *     * @return void     */    public function handle()    {        echo 'Event: UserCreated' . PHP_EOL;        echo json_encode($this-data) . PHP_EOL;        // TODO: Event User Created    }}
 
BankExtreJob::dispatch( $exception)-onConnection('rabbitmq')-onQueue('default');
EventServiceProvider.php
public function boot(){    \\App::bindMethod(TestJob::class . '@handle', fn($job) = $job-handle());}