forumhouseteam / laravel-amqp
v3.1.1
2019-06-25 08:57 UTC
Requires
- php: >=7.1
- ext-json: *
- php-amqplib/php-amqplib: 2.6.*
Requires (Dev)
- laravel/framework: >=5.7.0
- orchestra/testbench: 3.8.*
- squizlabs/php_codesniffer: 1.*
Suggests
- ext-posix: Restart workers if connection is lost to avoid unlimited loop
README
AMQP 驱动程序用于 Laravel 队列。此驱动程序使用流行的 AMQPLib for PHP:https://github.com/videlalvaro/php-amqplib(此库是 AMQP 协议的纯 PHP 实现,因此可以用于连接到多个队列管理器)
安装
请注意,包名已更改为 fhteam/laravel-amqp。 虽然旧名称仍然可以使用,但将不再维护。
- 简单的 composer 安装即可:
composer require fhteam/laravel-amqp:~1.0
(设置版本要求为您的首选) - 注意,php-amqplib 正常工作需要 mbstring 和 bcmath 扩展。第一个尚未在库的 composer.json 中列出(https://github.com/videlalvaro/php-amqplib/issues/229)
配置
在您的 config/queue.php
文件中,您必须提供以下内容
'default' => 'amqp', 'connections' => array( 'amqp' => array( 'driver' => 'amqp', 'host' => 'localhost', 'port' => '5672', 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', 'queue' => null, 'queue_flags' => ['durable' => true, 'routing_key' => null], //Durable queue (survives server crash) 'declare_queues' => true, //If we need to declare queues each time before sending a message. If not, you will have to declare them manually elsewhere 'message_properties' => ['delivery_mode' => 2], //Persistent messages (survives server crash) 'channel_id' => null, 'exchange_name' => null, 'exchange_type' => null, 'exchange_flags' => null, 'keepalive' > false, 'heartbeat' => 0, 'retry_after' => 0, ), ),
在您的 config/app.php
中,将 'Forumhouse\LaravelAmqp\ServiceProvider\LaravelAmqpServiceProvider'
添加到已注册的服务提供者列表中。
改进的工作稳定性(需要 PHP 7.1+)
为了获得更好的稳定性,请在 app/Exceptions/Handler.php 中添加以下代码
class Handler extends ExceptionHandler {
到
class Handler extends ExceptionHandler { use AMQPFailureDetector;
并且
public function report(Exception $exception) { parent::report($exception); }
到
public function report(Exception $exception) { $this->catchAMQPConnectionFailure($exception); parent::report($exception); }
用法
有关如何使用 Laravel 队列的详细信息,请参阅以下官方文档:https://laravel.net.cn/docs/queues