sima-land/yii2-amqp

Yii2 AMQP extension (wrapper on php-amqplib).

Installs: 3 336

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 10

Forks: 1

Open Issues: 4

Type:yii2-extension

v0.4.0 2021-03-14 11:55 UTC

README

Yii2 AMQP extension

Installation

You need run just this command:

composer require sima-land/yii2-amqp

Configuration

Example configuration:

return [
    'components' => [
        'amqp' => [
            'class' => \simaland\amqp\Component::class,
            'connection' => [
                'dsn' => 'amqp://user:password@host:port/vHost?<param>=<value>'
            ],
            'queues' => [
                [
                    'name' => 'queueName',
                ],
            ],
            'exchanges' => [
                [
                    'name' => 'exchangeName',
                ],
            ],
            'routing' => [
                [
                    'sourceExchange' => 'exchangeName',
                    'targetQueue' => 'queueName',
                ],
            ],
            'consumer' => [
                'callbacks' => [
                    'queueName' => <implement of \simaland\amqp\components\consumer\CallbackInterface::class>,
                ],
            ],
        ],
    ],
];

Testing

You must tests your changes by running this command:

composer test

Example

class AmpqController {

    public function actionSend()
    {
        $msg = \Yii::$app->amqp->createMessage('Test');
        $exchange = \Yii::$app->amqp->exchanges->current();
        $exchange->declare();
        \Yii::$app->amqp->producer->publish($msg, $exchange);
    }

    public function actionListen()
    {
        \Yii::$app->amqp->consumer->declare();
        \Yii::$app->amqp->consumer->consume();
    }