g4 / messenger
RMQ messenger
1.0.3
2022-03-30 13:42 UTC
Requires
- ext-json: *
- ext-pdo: *
- ext-redis: *
- php-amqplib/php-amqplib: >=2.6.1
Requires (Dev)
- g4/code-coverage: 1.*
- phpunit/phpunit: 5.*
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-08-29 05:43:29 UTC
README
消息库
安装
通过 Composer
composer require g4/messenger
要运行 rbmq 消息表,请执行
php vendor/bin/messenger-create-table --dbname your_db_name --dbport your_db_port --username your_db_username --password your_db_password --host your_db_host
用法
<?php // create \PDO object with your db params $pdo = new \PDO('mysql:dbname=db;host=127.0.0.1:3306', 'root', '1234'); // publish singe message to RabbitMq with your RabbitMq params (new \G4\Messenger\RabbitMQ\RabbitMq( 'your_exchange', 'your_binding', $pdo ))->sendMessage(['foo' => 'baz']); // publish bulk messages to RabbitMq with your RabbitMq params (new \G4\Messenger\RabbitMQ\RabbitMq( 'your_exchange', 'your_binding', $pdo ))->sendMessageBulk( [ ['foo1' => 'baz1'], ['foo2' => 'baz2'], ['foo3' => 'baz3'], ] ); // create your AMQP connection based on your params $connection = new PhpAmqpLib\Connection\AMQPStreamConnection( 'localhost', '5672', 'guest', 'guest' ); // restore your undelivered message from db and put them back to RBMQ (new \G4\Messenger\Messenger\Messenger( $pdo, $connection ))->restoreMessages(); ?>
开发
安装依赖项
$ make install
运行测试
$ make unit-tests