docker+laravel+rabbitmq 搭建記錄

auth_openid發表於2021-11-10

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
  • 現在你可以使用 rabbitmq 作為驅動,使用佇列功能啦 ~

docker+laravel+rabbitmq 搭建記錄
-部分參考 www.kuangstudy.com/zl/rabbitmq#136...

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章