forumhouseteam / xenforo-amqp
v1.0.0
2015-03-04 08:53 UTC
Requires
- videlalvaro/php-amqplib: ~2.4
Requires (Dev)
- zendframework/zendframework1: ~1.12
This package is not auto-updated.
Last update: 2019-02-20 18:21:29 UTC
README
为 XenForo 提供的 AMQP 客户端库,用于连接 RabbitMQ 等服务器
安装
请注意,包名已更改为 fhteam/xenforo-amqp
。 虽然旧名称仍然可以使用,但将不再维护。
该库遵循 PSR4 标准,因此安装方式与我们在所有 XenForo 扩展中看到的不同
因此,要使用此库,您可以直接将脚本包含到您的源代码中,或者执行以下操作
- 将 composer 安装到您的系统或 XenForo 根目录:[https://getcomposer.org.cn/doc/00-intro.md#installation-linux-unix-osx](https://getcomposer.org.cn/doc/00-intro.md#installation-linux-unix-osx)
- 在 XenForo 根目录中运行
composer init
以创建 composer.json:[https://getcomposer.org.cn/doc/03-cli.md#init](https://getcomposer.org.cn/doc/03-cli.md#init) - 运行
composer require --update-no-dev fhteam/xenforo-amqp:dev-master
以安装此包(--update-no-dev
跳过仅用于语法高亮的包,如 Zend Framework):[https://getcomposer.org.cn/doc/03-cli.md#require](https://getcomposer.org.cn/doc/03-cli.md#require) - 在您的
library/config.php
文件的末尾添加一行require_once(__DIR__ . '/../vendor/autoload.php');
以将 composer 自动加载器添加到 XenForo 的自动加载链中 - 现在您可以在开发过程中使用所有 composer 包(包括我们的包),并使用 composer 可执行文件轻松管理它们
配置
在您的 library/config.php
文件的末尾添加以下行
//============ AMQP connector settings ============ $config['amqp'] = array( 'host' => '192.168.1.1.1', // The host where your AMPQ-compatible server runs 'port' => '5672', // Port, your server runs on 'user' => 'user', // Authentication user name 'password' => 'password', // Authentication password 'queues' => array( // Queues configuration 'auth_ban' => array( // The name of the queue 'queue_flags' => array( // Queue flags. 'durable' => true, // 'durable' means the queue will survice server reboot ), ), ), );
使用
- 创建管理实例
$manager = new \Forumhouse\XenForoAmqp\QueueManager();
- 将消息推送到队列
$manager->pushMessage( 'my_queue_name', // The name of the queue. Must be in configuration file (see above) array('data' => 'test_data'), // The data to send to the queue. Will be json_encode'd if array is provided array('delivery_mode' => 2) // Message properties. 'delivery_mode' => 2 makes message persistent );