Docker 安装 RabbitMQ

docker run -di --name myrabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 -p 25672:25672 -p 61613:61613 -p 1883:1883 rabbitmq:management


客户端访问
 

http://127.0.0.1:15672/ (admin admin)


laravel 安装扩展

composer require vladimir-yuldashev/laravel-queue-rabbitmq:*


tips: 注意后面那个 *
修改 config/queue.php

'rabbitmq' => [
  'driver' => 'rabbitmq',

  'host' => env('RABBITMQ_HOST', '127.0.0.1'),
  'port' => env('RABBITMQ_PORT', 5672),

  'vhost' => env('RABBITMQ_VHOST', '/'),
  'login' => env('RABBITMQ_USER', 'guest'),
  'password' => env('RABBITMQ_PASSWORD', 'guest'),

  'queue' => env('RABBITMQ_QUEUE','default'), // name of the default queue,

  'exchange_declare' => env('RABBITMQ_EXCHANGE_DECLARE', true), // create the exchange if not exists
  'queue_declare_bind' => env('RABBITMQ_QUEUE_DECLARE_BIND', true), // create the queue if not exists and bind to the exchange

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

  'exchange_params' => [
  'name' => env('RABBITMQ_EXCHANGE_NAME', null),
  'type' => env('RABBITMQ_EXCHANGE_TYPE', 'direct'), // more info at http://www.rabbitmq.com/tutorials/amqp-concepts.html
  'passive' => env('RABBITMQ_EXCHANGE_PASSIVE', false),
  'durable' => env('RABBITMQ_EXCHANGE_DURABLE', true), // the exchange will survive server restarts
  'auto_delete' => env('RABBITMQ_EXCHANGE_AUTODELETE', false),
  ],

]

修改 .env
 

QUEUE_DRIVER=rabbitmq
RABBITMQ_HOST=192.168.31.206    #避坑
RABBITMQ_PORT=5672
RABBITMQ_VHOST=/
RABBITMQ_USER=admin            # 避坑
RABBITMQ_PASSWORD=admin
RABBITMQ_QUEUE=test4488