PHPackages                             cjieyan/laravel-queue-cmq - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. cjieyan/laravel-queue-cmq

ActiveLibrary

cjieyan/laravel-queue-cmq
=========================

Queue Adapter for Tencent Qcloud CMQ SDK

6.0.0(4y ago)02MITPHPPHP ^7.2

Since Nov 17Pushed 4y agoCompare

[ Source](https://github.com/cjieyan/laravel-queue-cmq)[ Packagist](https://packagist.org/packages/cjieyan/laravel-queue-cmq)[ RSS](/packages/cjieyan-laravel-queue-cmq/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (32)Used By (0)

 [![](https://camo.githubusercontent.com/39bc2b77da3880b2b3c1c7352f983e5a6b804f882600e1cd08ad86b05f5793e9/68747470733a2f2f696d6763616368652e71712e636f6d2f6f70656e5f70726f6a2f70726f6a5f71636c6f75645f76322f696e7465726e6174696f6e616c2f646f632f6373732f696d672f69636f6e2f69636f6e2d7a7a6a2e737667)](https://camo.githubusercontent.com/39bc2b77da3880b2b3c1c7352f983e5a6b804f882600e1cd08ad86b05f5793e9/68747470733a2f2f696d6763616368652e71712e636f6d2f6f70656e5f70726f6a2f70726f6a5f71636c6f75645f76322f696e7465726e6174696f6e616c2f646f632f6373732f696d672f69636f6e2f69636f6e2d7a7a6a2e737667)

Tencent Cloud Message Queue Driver for Laravel Queue

 [ ![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) ](LICENSE) [ ![Build Status](https://camo.githubusercontent.com/395196ef4faf5bd40aa758ead6f89beaac857820ec9abf51d3581b6d0f92d632/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f667265796f2f6c61726176656c2d71756575652d636d712f6d61737465722e7376673f7374796c653d666c61742d737175617265) ](https://travis-ci.org/freyo/laravel-queue-cmq) [ ![Coverage Status](https://camo.githubusercontent.com/73e15aa2add8c870c5fef76943428f3d2a77aa998ac61c2b2acaa66ee7101e01/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f667265796f2f6c61726176656c2d71756575652d636d712e7376673f7374796c653d666c61742d737175617265) ](https://scrutinizer-ci.com/g/freyo/laravel-queue-cmq) [ ![Quality Score](https://camo.githubusercontent.com/195c89e9822678ff02763cbde70a81b8a66eb1d13a3239e1bc404e59363f4ac5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f667265796f2f6c61726176656c2d71756575652d636d712e7376673f7374796c653d666c61742d737175617265) ](https://scrutinizer-ci.com/g/freyo/laravel-queue-cmq) [ ![Packagist Version](https://camo.githubusercontent.com/cb8d6fd652446144d8e904e66461a0272a4413821d29bb6eae6820e6f114c260/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f667265796f2f6c61726176656c2d71756575652d636d712e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/freyo/laravel-queue-cmq) [ ![Total Downloads](https://camo.githubusercontent.com/37255634a782c4cb8f48f6b9edb8e0e646ac7bc9f63ada2194fcbd21c88649f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f667265796f2f6c61726176656c2d71756575652d636d712e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/freyo/laravel-queue-cmq)

 [ ![FOSSA Status](https://camo.githubusercontent.com/321cc1937a568b08620df0896c77171b18f5ce589f6d1978fc220c2eca384902/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246667265796f2532466c61726176656c2d71756575652d636d712e7376673f747970653d736d616c6c) ](https://app.fossa.io/projects/git%2Bgithub.com%2Ffreyo%2Flaravel-queue-cmq?ref=badge_small)

Installation
------------

[](#installation)

```
composer require freyo/laravel-queue-cmq
```

Configure
---------

[](#configure)

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

1. `config/app.php`:

```
'providers' => [
  // ...
  LaravelQueueCMQ\LaravelQueueCMQServiceProvider::class,
]
```

2. `.env`:

```
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

[](#tips)

- Region should be replaced with a specific region: gz (Guangzhou), sh (Shanghai), or bj (Beijing).
- Domain for public network API request: cmq-queue-region.api.qcloud.com / cmq-topic-region.api.qcloud.com
- Domain for private network API request: cmq-queue-region.api.tencentyun.com / cmq-topic-region.api.tencentyun.com

Usage
-----

[](#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:

### Example

[](#example)

#### Dispatch Jobs

[](#dispatch-jobs)

The default connection name is `cmq`

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

//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'))

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

#### Multiple Queues

[](#multiple-queues)

Configure `config/queue.php`

```
'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

[](#process-jobs)

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

#### Plain Mode

[](#plain-mode)

Configure `.env`

```
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.

```
