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
Requires
- php: >=7.1
- ext-json: *
- php-amqplib/php-amqplib: v2.12.3
- yiisoft/yii2: ^2.0.15
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^7.5
- roave/security-advisories: dev-master
Suggests
- ext-pcntl: Use pcntl extension
- ext-posix: Use posix extension
This package is auto-updated.
Last update: 2024-10-21 23:15:41 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(); }