Download the PHP package jcleng/think-queue-rabbitmq without Composer
On this page you can find all versions of the php package jcleng/think-queue-rabbitmq. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jcleng/think-queue-rabbitmq
More information about jcleng/think-queue-rabbitmq
Files in jcleng/think-queue-rabbitmq
Package think-queue-rabbitmq
Short Description 为 ThinkPH5.0 队列增加 RabbitMQ 驱动(forked https://github.com/jayazhao/think-queue-rabbitmq)
License Apache-2.0
Informations about the package think-queue-rabbitmq
快速接入tp5.0的项目
配置
配置文件位于
application/extra/queue.php
,消费类Job1
使用不变
驱动配置
创建任务类
单模块项目推荐使用
app\job
作为任务类的命名空间 多模块项目可用使用app\module\job
作为任务类的命名空间 也可以放在任意可以自动加载到的地方
任务类不需继承任何类,如果这个类只有一个任务,那么就只需要提供一个fire
方法就可以了,如果有多个小任务,就写多个方法,下面发布任务的时候会有区别
每个方法会传入两个参数 think\queue\Job $job
(当前的任务对象) 和 $data
(发布任务时自定义的数据)
还有个可选的任务失败执行的方法 failed
传入的参数为$data
(发布任务时自定义的数据)
下面写两个例子
发布任务
推送
queue("Job1", ["name"=> "张三"]);
think\Queue::push($job, $data = '', $queue = null)
和think\Queue::later($delay, $job, $data = '', $queue = null)
两个方法,前者是立即执行,后者是在$delay
秒后执行
$job
是任务名
单模块的,且命名空间是app\job
的,比如上面的例子一,写Job1
类名即可
多模块的,且命名空间是app\module\job
的,写model/Job1
即可
其他的需要些完整的类名,比如上面的例子二,需要写完整的类名app\lib\job\Job2
如果一个任务类里有多个小任务的话,如上面的例子二,需要用@+方法名app\lib\job\Job2@task1
、app\lib\job\Job2@task2
$data
是你要传到任务里的参数
$queue
队列名,指定这个任务是在哪个队列上执行,同下面监控队列的时候指定的队列名,可不填
监听任务并执行
php think queue:listen
php think queue:work --daemon(不加--daemon为执行单个任务)
php think queue:work --queue queue_default --daemon
两种,具体的可选参数可以输入命令加 --help 查看
可配合supervisor使用,保证进程常驻
- supervisord.conf原文
All versions of think-queue-rabbitmq with dependencies
topthink/think-installer Version >=1.0.10
topthink/framework Version ~5.0.0
topthink/think-queue Version 1.1.*
enqueue/amqp-lib Version ^0.9.8