yiisolutions / yii2-queue
Extension for work with queues
Installs: 253
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php-amqplib/php-amqplib: >=2.6.1
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2024-11-06 00:57:47 UTC
README
Extension for work with queues.
Installation
Use composer
composer require "yiisolutions/yii2-migrations-advanced: *"
or add to composer.json require section:
"yiisolutions/yii2-migrations-advanced": "*"
Configuration
First, we add to the configuration component.
<?php return [ // ... 'components' => [ // ... 'queue' => [ 'class' => 'yisolutions\queue\Queue', 'host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', ], // ... ], // ... ];
Send data
Next, to send data to the queue, we use the send() component method.
<?php use yiisolutions\queue\Queue; // ... $data = ['foo' => 'bar']; /** @var Queue $queue */ $queue = Yii::$app->get('queue'); $queue->send('queue.name', $data);
Receive data
We use the listen method to retrieve data.
<?php use yiisolutions\queue\Queue; use PhpAmqpLib\Message\AMQPMessage; // ... /** @var Queue $queue */ $queue = Yii::$app->get('queue'); $queue->listen('queue.name', function(AMQPMessage $msg) use ($queue) { // process data // acknowledgment message $queue->acknowledgmentMessage($msg); });