Yii Queue provides several console commands for processing queued messages.
If you are using yiisoft/config and yiisoft/yii-console, the commands are registered automatically.
If you are using symfony/console directly, you should register the commands manually.
Note: The default queue name list (used when no queue names are passed to a command) is only available when using yiisoft/config and yiisoft/yii-console. Without them, you must pass the queue name list explicitly to the command constructor.
In yiisoft/app the yii console binary is provided out of the box.
If you are using yiisoft/yii-console or symfony/console without that template, invoke these commands the same way you invoke other console commands in your application.
The command queue:run obtains and handles messages until the queue is empty, then exits.
You can also narrow the scope of processed messages by specifying queue name(s) and maximum number of messages to process:
- Specify one or more queue names to process. Messages from other queues will be ignored. Defaults to all registered queue names.
- Use
--limitto limit the number of messages processed. When set, command will exit either when all the messages are processed or when the maximum count is reached.
The full command signature is:
yii queue:run [queueName1 [queueName2 [...]]] --limit=100The following command launches a daemon, which infinitely consumes messages from a single queue. This command receives an optional queueName argument to specify which queue to listen to, defaults to the queue name yii-queue.
yii queue:listen [queueName]Note: If the queue is not configured with an adapter (synchronous mode), the command logs an info message and exits gracefully.
The following command iterates through multiple queues and is meant to be used in development environment only, as it consumes a lot of CPU for iterating through queues. You can pass to it:
queueNameargument(s). Specify one or more queue names to process. Messages from other queues will be ignored. Defaults to all registered queue names.--limitoption to limit the number of messages processed before switching to another queue. E.g. you set--limitto 500 and right now you have 1000 messages inqueue1. This command will consume only 500 of them, then it will switch toqueue2to see if there are any messages there. Defaults to0(no limit).--pauseoption to specify the number of seconds to pause between checking queues when no messages are found. Defaults to1.
The full command signature is:
yii queue:listen-all [queueName1 [queueName2 [...]]] --pause=1 --limit=0For long-running processes, graceful shutdown is controlled by LoopInterface. When ext-pcntl is available,
the default SignalLoop handles signals such as SIGTERM/SIGINT.