fhteam/laravel-amqp

Laravel 队列的 AMQP 库驱动程序

v3.1.1 2019-06-25 08:57 UTC

This package is auto-updated.

Last update: 2024-09-25 20:36:23 UTC


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 中列出(php-amqplib/php-amqplib#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