strong2much/yii2-queue

Helper classes for working with google products and technologies

dev-master 2016-08-29 19:13 UTC

This package is auto-updated.

Last update: 2024-11-05 07:23:32 UTC


README

This extension is using for works with different message queue services.

Installation

Install package by composer

{
    "require": {
       "strong2much/yii2-queue": "dev-master"
    }
}

Or

$ composer require strong2much/yii2-queue "dev-master"

Use the following code in your configuration file. You can use different services

'queue' => [
    'class' => 'strong2much\queue\QueueManager'
    'serviceConfig' => [
        'class' => 'strong2much\queue\services\DummyQueue',
    ]
]

Then you can send messages like so:

$msg = new \strong2much\queue\messages\TestMessage();
$msg->id = 1;
$msg->message = "Some text";
if($msg->send()) {
    echo "OK";
}

Then you can use manager to handle your messages

//To receive messages
$route = 'mq_test'; //just for example
$message = Yii::$app->queue->receiveMessage($route); //this will get first  one message from the queue

//if you specify some processing function in message model,
//then you can call it like so
if($message !== false) {
	Yii::app()->queue->processData($route, \yii\base\helpers\Json::decode($message));
}

In order to use DbQueue as your service, you will need to apply the provided migrations.