|
| 1 | +--- |
| 2 | +group: configuration-guide |
| 3 | +title: Manage message queues |
| 4 | +functional_areas: |
| 5 | + - Configuration |
| 6 | + - System |
| 7 | + - Setup |
| 8 | +--- |
| 9 | + |
| 10 | + |
| 11 | +If you don't want to implement the RabbitMQ solution, you can manage message queues with cron jobs (or an external process manager) and the command line to ensure that consumers are retrieving messages. |
| 12 | + |
| 13 | +## Process management |
| 14 | + |
| 15 | +Cron jobs are the default mechanism to restart consumers. Processes started by `cron` consume the specified number of messages and then terminate. Re-running `cron` restarts the consumer. |
| 16 | + |
| 17 | +The following shows a `crontab` configuration for running consumers in our implementation, it is the example for understanding how it works: |
| 18 | + |
| 19 | +*/app/code/Magento/MessageQueue/etc/crontab.xml* |
| 20 | + |
| 21 | +```xml |
| 22 | +... |
| 23 | +<job name="consumers_runner" instance="Magento\MessageQueue\Model\Cron\ConsumersRunner" method="run"> |
| 24 | + <schedule>* * * * *</schedule> |
| 25 | +</job> |
| 26 | +... |
| 27 | +``` |
| 28 | + |
| 29 | +{:.bs-callout .bs-callout-info} |
| 30 | +How often you check message queues depends on your business logic and available system resources. In general, you'll probably want to check for newly created customers and send welcome emails more frequently than a more resource intensive process (e.g., updating your catalog). You should define `cron` schedules according to your business needs.<br><br>It can be configured in Admin Panel **Stores > Configuration > Advanced > System > Cron configuration options for group: consumers**<br><br>See [Configure and run cron]({{ page.baseurl }}/config-guide/cli/config-cli-subcommands-cron.html) for more information about using `cron` with Magento. |
| 31 | + |
| 32 | +You can also use a process manager such as [Supervisor](http://supervisord.org/index.html) to monitor the status of processes. The manager can use the command line to restart the processes as needed. |
| 33 | + |
| 34 | +### Configuration |
| 35 | + |
| 36 | +#### Behavior by default |
| 37 | + |
| 38 | +* Cron job `consumers_runner` is enabled |
| 39 | +* Cron job `consumers_runner` runs all defined consumers |
| 40 | +* Each consumer process 10000 messages and then terminate |
| 41 | + |
| 42 | +#### Specific configuration |
| 43 | + |
| 44 | +Edit */app/etc/env.php* file for configure cron job `consumers_runner` |
| 45 | + |
| 46 | +{% highlight php %} |
| 47 | +... |
| 48 | + 'cron_consumers_runner' => array( |
| 49 | + 'cron_run' => false, |
| 50 | + 'max_messages' => 20000, |
| 51 | + 'consumers' => array( |
| 52 | + 'consumer1', |
| 53 | + 'consumer2', |
| 54 | + ) |
| 55 | + ), |
| 56 | +... |
| 57 | +{% endhighlight %} |
| 58 | + |
| 59 | +* `cron_run` - the option for enabling/disabling cron job `consumers_runner`, by default is true. |
| 60 | +* `max_messages` - the maximum number of messages for each consumer that must be processed before consumer terminate, by default is 1000. If it is 0, then the consumer never stops working. |
| 61 | +* `consumers` - the list of consumers which will be run, by default is empty array (all consumers are allowed to be run). |
| 62 | + |
| 63 | +{% include config/message-queue-consumers.md %} |
| 64 | + |
| 65 | +#### Related Topics |
| 66 | + |
| 67 | +* [Message Queues Overview]({{ page.baseurl }}/config-guide/mq/rabbitmq-overview.html) |
| 68 | +* [Configure and run cron]({{ page.baseurl }}/config-guide/cli/config-cli-subcommands-cron.html) |
| 69 | +* [Command-line configuration]({{ page.baseurl }}/config-guide/cli/config-cli-subcommands.html) |
| 70 | +* [Message Queues]({{ page.baseurl }}/extension-dev-guide/message-queues/message-queues.html) |
0 commit comments