inna/think-rabbit-queue

RabbitMQ Queue for ThinkPHP.

1.0.2 2021-09-15 03:37 UTC

This package is auto-updated.

Last update: 2024-04-29 04:47:19 UTC


README

RabbitMQ Queue for ThinkPHP 5.

Installation

$ composer require inna/think-rabbit-queue

Usage

<?php

use Inna\RabbitQueue\Job;
use Inna\RabbitQueue\ShouldQueue;

class CancelOrderJob extends Job implements ShouldQueue
{
    public $order;
    
    public function __construct($order)
    {
        $this->order = $order;
    }

    public function handle() 
    {
        if ($this->order->shouldCancel()) {
            $this->order->cancel();
        }
    }
}
<?php

use Carbon\Carbon;
use Inna\RabbitQueue\Queue;

$order = Order::find(1);

$job = (new CancelOrderJob($order))->delay(Carbon::now()->addDays(7));

$job->dispatch();
<?php

use Inna\RabbitQueue\Queue;

Queue::consume();