Download the PHP package linzc/think-queue-rabbitmq without Composer

On this page you can find all versions of the php package linzc/think-queue-rabbitmq. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package think-queue-rabbitmq

RabbitMQ driver for ThinkPHP6 Queue.

安装

composer require linzc/think-queue-rabbitmq

配置

公共配置

添加连接到config/queue.php:

可选配置

可以选择将队列选项添加到连接的配置中。为此连接创建的每个队列,都获取属性。

如果您想在消息延迟时对其进行优先级排序,则可以通过添加额外选项来实现。

当您想针对带有路由密钥的交换发布消息时,可以通过添加额外的选项来实现。

注意:当使用 exchange 和 routing-key 时,你需要创建带有绑定的队列。

在 ThinkPHP 中,失败的作业被存储到数据库中。但也许您想指示其他进程也对消息进行处理。当您想指示 RabbitMQ 将失败的消息重新路由到交换器或特定队列时,可以通过添加额外的选项来实现。

注意:当使用 exchange 和 routing-key 时,你需要创建带有绑定的交换机/队列。

创建任务类

单模块项目推荐使用 app\job 作为任务类的命名空间 多模块项目可用使用 app\module\job 作为任务类的命名空间 也可以放在任意可以自动加载到的地方

任务类不需继承任何类,如果这个类只有一个任务,那么就只需要提供一个fire方法就可以了,如果有多个小任务,就写多个方法,下面发布任务的时候会有区别
每个方法会传入两个参数 think\queue\Job $job(当前的任务对象) 和 $data(发布任务时自定义的数据)

还有个可选的任务失败执行的方法 failed 传入的参数为$data(发布任务时自定义的数据)

下面写两个例子

发布任务

think\facade\Queue::push($job, $data = '', $queue = null)think\facade\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@task1app\lib\job\Job2@task2

$data 是你要传到任务里的参数

$queue 队列名,指定这个任务是在哪个队列上执行,同下面监控队列的时候指定的队列名,可不填

消费消息

有两种消费消息的方式。

具体的可选参数可以输入命令加 --help 查看

可配合supervisor使用,保证进程常驻

其他命令


All versions of think-queue-rabbitmq with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
php-amqplib/php-amqplib Version ^3.0
topthink/think-queue Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package linzc/think-queue-rabbitmq contains the following files

Loading the files please wait ....