2017 © Pedro Peláez
 

library laravel-queue-cmq

Queue Adapter for Tencent Qcloud CMQ SDK

image

freyo/laravel-queue-cmq

Queue Adapter for Tencent Qcloud CMQ SDK

  • Sunday, July 29, 2018
  • by freyo
  • Repository
  • 2 Watchers
  • 6 Stars
  • 675 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 16 Versions
  • 73 % Grown

The README.md

, (*1)

Tencent Cloud Message Queue Driver for Laravel Queue, (*2)

Software License Build Status Coverage Status Quality Score Packagist Version Total Downloads , (*3)

FOSSA Status , (*4)

Installation

shell composer require freyo/laravel-queue-cmq, (*5)

Configure

Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider., (*6)

  1. config/app.php:, (*7)

    'providers' => [
    // ...
    Freyo\LaravelQueueCMQ\LaravelQueueCMQServiceProvider::class,
    ]
    
  2. .env:, (*8)

    QUEUE_DRIVER=cmq
    
    CMQ_SECRET_KEY=
    CMQ_SECRET_ID=
    
    CMQ_QUEUE_HOST=https://cmq-queue-{region}.api.qcloud.com
    CMQ_QUEUE=queue_name #default queue name
    CMQ_QUEUE_POLLING_WAIT_SECONDS=0
    
    CMQ_TOPIC_ENABLE=false # set to true to use topic
    CMQ_TOPIC_FILTER=routing # or msgtag
    CMQ_TOPIC_HOST=https://cmq-topic-{region}.api.qcloud.com
    CMQ_TOPIC=topic_name
    

Tips

  • Region should be replaced with a specific region: gz (Guangzhou), sh (Shanghai), or bj (Beijing)., (*9)

  • Domain for public network API request: cmq-queue-region.api.qcloud.com / cmq-topic-region.api.qcloud.com, (*10)

  • Domain for private network API request: cmq-queue-region.api.tencentyun.com / cmq-topic-region.api.tencentyun.com, (*11)

Usage

Once you completed the configuration you can use Laravel Queue API. If you used other queue drivers you do not need to change anything else. If you do not know how to use Queue API, please refer to the official Laravel documentation: http://laravel.com/docs/queues, (*12)

Example

Dispatch Jobs

The default connection name is cmq, (*13)

```php //use queue only Job::dispatch()->onConnection('connection-name')->onQueue('queue-name'); // or dispatch((new Job())->onConnection('connection-name')->onQueue('queue-name')), (*14)

//use topic and tag filter Job::dispatch()->onConnection('connection-name')->onQueue('tag1,tag2,tag3'); // or dispatch((new Job())->onConnection('connection-name')->onQueue('tag1,tag2,tag3')), (*15)

//use topic and routing filter Job::dispatch()->onConnection('connection-name')->onQueue('routing-key'); // or dispatch((new Job())->onConnection('connection-name')->onQueue('routing-key')) ```, (*16)

Multiple Queues

Configure config/queue.php, (*17)

'connections' => [
    //...
    'new-connection-name' => [
        'driver' => 'cmq',
        'secret_key' => 'your-secret-key',
        'secret_id'  => 'your-secret-id',
        'queue' => 'your-queue-name',
        'options' => [
            'queue' => [
                'host'                 => 'https://cmq-queue-region.api.qcloud.com',
                'name'                 => 'your-queue-name',
                'polling_wait_seconds' => 0, // 0-30 seconds
                'retries'              => 3,
            ],
            'topic' => [
                'enable'  => false,
                'filter'  => 'routing', // routing or msgtag
                'host'    => 'https://cmq-topic-region.api.qcloud.com',
                'name'    => 'your-topic-name',
                'retries' => 3,
            ],
        ],
        'plain' => [
            'enable' => false,
            'job' => 'App\Jobs\CMQPlainJob@handle',
        ],
    ];
    //...
];

Process Jobs

php artisan queue:work {connection-name} --queue={queue-name}

Plain Mode

Configure .env, (*18)

CMQ_PLAIN_ENABLE=true
CMQ_PLAIN_JOB=App\Jobs\CMQPlainJobHandler@handle

Create a job implements PlainPayload interface. The method getPayload must return a sting value., (*19)

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Freyo\LaravelQueueCMQ\Queue\Contracts\PlainPayload;

class CMQPlainJob implements ShouldQueue, PlainPayload
{
    use Dispatchable, InteractsWithQueue, Queueable;

    protected $payload;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($payload)
    {
        $this->payload = $payload;
    }

    /**
     * Get the plain payload of the job.
     *
     * @return string
     */
    public function getPayload()
    {
        return $this->payload;
    }
}

Create a plain job handler, (*20)

<?php

namespace App\Jobs;

use Illuminate\Queue\Jobs\Job;

class CMQPlainJobHandler
{
    /**
     * Execute the job.
     * 
     * @param \Illuminate\Queue\Jobs\Job $job
     * @param string $payload
     * 
     * @return void
     */
    public function handle(Job $job, $payload)
    {
        // processing your payload...
        var_dump($payload);

        // release back to the queue manually when failed.
        // $job->release();

        // delete message when processed.
        if (! $job->isDeletedOrReleased()) {
            $job->delete();
        }        
    }
}

References

License

The MIT License (MIT). Please see License File for more information., (*21)

FOSSA Status, (*22)

The Versions

29/07 2018

dev-master

9999999-dev

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

09/06 2018

v5.4.x-dev

5.4.9999999.9999999-dev

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

09/06 2018

v5.5.x-dev

5.5.9999999.9999999-dev

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

07/06 2018

5.6.2

5.6.2.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

07/06 2018

5.4.6

5.4.6.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

07/06 2018

5.5.6

5.5.6.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

21/05 2018

5.4.5

5.4.5.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

21/05 2018

5.5.5

5.5.5.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

21/05 2018

5.6.1

5.6.1.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

28/04 2018

5.6.0

5.6.0.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

21/11 2017

5.5.4

5.5.4.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

21/11 2017

5.4.4

5.4.4.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

20/11 2017

5.4.1

5.4.1.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

20/11 2017

5.5.1

5.5.1.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

17/11 2017

5.5

5.5.0.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq

17/11 2017

5.4

5.4.0.0

Queue Adapter for Tencent Qcloud CMQ SDK

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar freyo

qcloud laravel-queue cmq