thinkphp6实战Rabbitmq之延时队列(完整篇)

1.安装延迟队列插件rabbitmq-delayed-message-exchange

https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases

thinkphp6实战Rabbitmq之延时队列(完整篇)_第1张图片

1.拷贝到对应rabbitmq容器中

docker cp rabbitmq_delayed_message_exchange-3.10.2.ez  rabbitmq:/plugins

2.进入容器

docker exec -it 容器id /bin/bash

3.启用插件

rabbitmq-plugins enable rabbitmq_delayed_message_exchange

4.重新启动容器

docker restart 容器id

2.创建交换器
thinkphp6实战Rabbitmq之延时队列(完整篇)_第2张图片
3.创建消费端脚本

php think make:command Ccomer comer

4.在项目 config/console.php 中的’commands’注册命令


 return [
  'commands' => [
        'comer' => \app\command\Comer::class,
  ]
];

5.安装php-amqplib插件

composer require php-amqplib/php-amqplib

6.config文件夹下新建rabbitmq.php文件rabbitMQ配置



return [

    'AMQP' => [
        'host' => '127.0.0.1',
        'port'=>'5672',
        'login'=>'guest',
        'password'=>'guest',
        'vhost'=>'/'
    ],

    'email_queue' => [
        'exchange_name' => 'delay-queue',
        'exchange_type'=>'direct',
        'queue_name' => 'email_queue',
        'route_key' => 'email_roteking',
        'consumer_tag' => 'consumer'
    ],
    
];

7.创建生产端逻辑


namespace app\controller;

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire

你可能感兴趣的:(thinkphp6,rabbitmq,php,docker)