Laravel安装RabbitMQ

一、安装RabbitMQ生产者
 

wget https://github.com/alanxz/rabbitmq-c/archive/v0.10.0.tar.gz
tar -zxvf v0.10.0.tar.gz
cd rabbitmq-c-0.10.0/
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c ..
cmake --build .  --target install
cd /usr/local/rabbitmq-c
ln -s lib64 lib

 

二、安装扩展

wget http://pecl.php.net/get/amqp-1.10.2.tgz
tar -zxvf amqp-1.10.2.tgz
cd amqp-1.10.2
/data/server/php7/bin/phpize
./configure --with-php-config=/data/server/php7/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c
make && make install
vi /data/server/php7/etc/php.ini
添加extension=amqp.so

 

三、安装Laravel扩展

composer require vladimir-yuldashev/laravel-queue-rabbitmq

修改config/queue.php文件在connections中追加

    'rabbitmq' => [

       'driver' => 'rabbitmq',
       'queue' => env('RABBITMQ_QUEUE', 'default'),
       'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,

       'hosts' => [
           [
               'host' => env('RABBITMQ_HOST', '127.0.0.1'),
               'port' => env('RABBITMQ_PORT', 5672),
               'user' => env('RABBITMQ_USER', 'abc'),
               'password' => env('RABBITMQ_PASSWORD', '123456'),
               'vhost' => env('RABBITMQ_VHOST', '/'),
           ],
       ],

       'options' => [
           'ssl_options' => [
               '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),
           ],
       ],

       /*
        * Set to "horizon" if you wish to use Laravel Horizon.
        */
       'worker' => env('RABBITMQ_WORKER', 'default'),

    ],

 

上一篇:Rabbitmq 简单示例


下一篇:新RabbitMQ精讲 提升工程实践能力 培养架构思维