rabbitmq php 驱动,Laravel Queue 的 RabbitMQ 驱动器

RabbitMQ Queue driver for Laravel

68747470733a2f2f706f7365722e707567782e6f72672f766c6164696d69722d79756c6461736865762f6c61726176656c2d71756575652d7261626269746d712f762f737461626c653f666f726d61743d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7679756c6461736865762f6c61726176656c2d71756575652d7261626269746d712e7376673f7374796c653d666c61742d73717561726568747470733a2f2f706f7365722e707567782e6f72672f766c6164696d69722d79756c6461736865762f6c61726176656c2d71756575652d7261626269746d712f646f776e6c6f6164733f666f726d61743d666c61742d73717561726568747470733a2f2f7374796c6563692e696f2f7265706f732f31343937363735322f736869656c6468747470733a2f2f706f7365722e707567782e6f72672f766c6164696d69722d79756c6461736865762f6c61726176656c2d71756575652d7261626269746d712f6c6963656e73653f666f726d61743d666c61742d737175617265

Installation

You can install this package via composer using this command:

composer require vladimir-yuldashev/laravel-queue-rabbitmq

The package will automatically register itself using Laravel auto-discovery.

Setup connection in config/queue.php

'connections' => [

// ...

'rabbitmq' => [

'driver' => 'rabbitmq',

'dsn' => env('RABBITMQ_DSN', null),

/*

* Could be one a class that implements \Interop\Amqp\AmqpConnectionFactory for example:

* - \EnqueueAmqpExt\AmqpConnectionFactory if you install enqueue/amqp-ext

* - \EnqueueAmqpLib\AmqpConnectionFactory if you install enqueue/amqp-lib

* - \EnqueueAmqpBunny\AmqpConnectionFactory if you install enqueue/amqp-bunny

*/

'factory_class' => Enqueue\AmqpLib\AmqpConnectionFactory::class,

'host' => env('RABBITMQ_HOST', '127.0.0.1'),

'port' => env('RABBITMQ_PORT', 5672),

'vhost' => env('RABBITMQ_VHOST', '/'),

'login' => env('RABBITMQ_LOGIN', 'guest'),

'password' => env('RABBITMQ_PASSWORD', 'guest'),

'queue' => env('RABBITMQ_QUEUE', 'default'),

'options' => [

'exchange' => [

'name' => env('RABBITMQ_EXCHANGE_NAME'),

/*

* Determine if exchange should be created if it does not exist.

*/

'declare' => env('RABBITMQ_EXCHANGE_DECLARE', true),

/*

* Read more about possible values at https://www.rabbitmq.com/tutorials/amqp-concepts.html

*/

'type' => env('RABBITMQ_EXCHANGE_TYPE', \Interop\Amqp\AmqpTopic::TYPE_DIRECT),

'passive' => env('RABBITMQ_EXCHANGE_PASSIVE', false),

'durable' => env('RABBITMQ_EXCHANGE_DURABLE', true),

'auto_delete' => env('RABBITMQ_EXCHANGE_AUTODELETE', false),

'arguments' => env('RABBITMQ_EXCHANGE_ARGUMENTS'),

],

'queue' => [

/*

* Determine if queue should be created if it does not exist.

*/

'declare' => env('RABBITMQ_QUEUE_DECLARE', true),

/*

* Determine if queue should be binded to the exchange created.

*/

'bind' => env('RABBITMQ_QUEUE_DECLARE_BIND', true),

/*

* Read more about possible values at https://www.rabbitmq.com/tutorials/amqp-concepts.html

*/

'passive' => env('RABBITMQ_QUEUE_PASSIVE', false),

'durable' => env('RABBITMQ_QUEUE_DURABLE', true),

'exclusive' => env('RABBITMQ_QUEUE_EXCLUSIVE', false),

'auto_delete' => env('RABBITMQ_QUEUE_AUTODELETE', false),

'arguments' => env('RABBITMQ_QUEUE_ARGUMENTS'),

],

],

/*

* Determine the number of seconds to sleep if there's an error communicating with rabbitmq

* If set to false, it'll throw an exception rather than doing the sleep for X seconds.

*/

'sleep_on_error' => env('RABBITMQ_ERROR_SLEEP', 5),

/*

* Optional SSL params if an SSL connection is used

* Using an SSL connection will also require to configure your RabbitMQ to enable SSL. More details can be founds here: https://www.rabbitmq.com/ssl.html

*/

'ssl_params' => [

'ssl_on' => env('RABBITMQ_SSL', false),

'cafile' => env('RABBITMQ_SSL_CAFILE', null),

'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),

'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),

'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),

'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),

],

],

// ...

],

Usage

Once you completed the configuration you can use Laravel Queue API. If you used other queue drivers you do not need to change anything else. If you do not know how to use Queue API, please refer to the official Laravel documentation: http://laravel.com/docs/queues

Using other AMQP transports

The package uses enqueue/amqp-lib transport which is based on php-amqplib. There is possibility to use any amqp interop compatible transport, for example enqueue/amqp-ext or enqueue/amqp-bunny. Here's an example on how one can change the transport to enqueue/amqp-bunny.

First, install desired transport package:

composer require enqueue/amqp-bunny:^0.8

Change the factory class in config/queue.php:

// ...

'connections' => [

'rabbitmq' => [

'driver' => 'rabbitmq',

'factory_class' => Enqueue\AmqpBunny\AmqpConnectionFactory::class,

],

],

Testing

You can run the tests with:

vendor/bin/phpunit

Contribution

You can contribute to this package by discovering bugs and opening issues. Please, add to which version of package you create pull request or issue. (e.g. [5.2] Fatal error on delayed job)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值