Download the PHP package run-as-root/magento2-message-queue-retry without Composer

On this page you can find all versions of the php package run-as-root/magento2-message-queue-retry. 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 magento2-message-queue-retry

Magento 2 PHP packagist build

run-as-root/magento2-message-queue-retry

It gives the possibility to process the same queue message more than once, utilizing The RabbitMQ's dead letter exchange feature.

Table of Contents


Prerequisites

To be able to use this module, you have to manually configure the dead letter exchange(s) for the queue(s) you want to enable the retry mechanismm through the queue_topology.xml file. An example will be given in the Configuration section.

Other requisite is that your exchanges have to have a relation from one exchange to only one topic and queue,

For example:

Installation

To install the module via composer:

To enable the module:


Features


How it works

The default Magento's consumer behavior is to reject the message when an exception is thrown during the consumer's execution. If you use a standard configuration for the queue (without a dead-letter exchange), the message will be discarded and not processed again.

This behavior will change a bit with this module. It will introduce an extra step that will check if the message has reached your retry limit, if so, it will be discarded from RabbitMQ and sent to the run_as_root_queue_error_message Mysql table and stay there until manual management through the admin panel.

If the message has not reached the retry limit, it will be rejected, and RabbitMQ will send it to the dead letter exchange. The message will be routed automatically to the "delay" queue and stay there until de TTL time is reached. After the TTL time is reached, the message will be returned to its original queue.

The diagram below illustrates both approaches:

In the admin panel a new grid will be available to manage the messages that have reached the retry limit:

Path: RunAsRoot > Manage Messages

The grid colums:

The grid actions:

The grid also has a mass action to delete or requeue the selected messages.

Is possible to configure the ACL for each action in the grid and the module configuration:


Configuration

Two steps are necessary to configure the retry for a queue:

  1. Configure the dead letter exchange
  2. Declare the retry limit xml configuration
  3. Enable the message queue retry admin configuration

1. Configuring the dead letter exchange

Let's imagine a scenario that the erp_order_export queue already exists in your project and to simplify the example the topic name, exchange name and queue name are the same: erp_order_export.

We need to change these two files in order to declare and configure the delay queue:

The current queue configuration are like this:

etc/communication.xml:

etc/queue_topology.xml:

You have to change it to:

etc/communication.xml:

etc/queue_topology.xml:

In the erp_order_export exchange binding, we added the x-dead-letter-exchange and x-dead-letter-routing-key arguments, this will route the message to the erp_order_export_delay exchange when the message is rejected.

We added the erp_order_export_delay exchange and binding, it points to the original exchange (erp_order_export). the x-message-ttl argument will configure the period that the message will stay in the erp_order_export_delay queue, in this example for 5 minutes (300000ms). When the lifetime expires (TTL), RabbitMQ will send the message to erp_order_export automatically.

The erp_order_export_delay queue does not have a consumer, it will be used only to hold(delay) messages according with the period defined in the x-message-ttl argument.

2. Declaring the retry limit xml configuration

Create the Vendor_ModuleName/etc/queue_retry.xml file with the content:

3. Enabling the message queue retry admin configuration

Now you have to toggle the activation for the retry queue module:

System > Configuration > RUN-AS-ROOT > Message Queue Retry

Note: The configuration Total of days to keep the messages is the period that the messages will stay in the database. After this period, the messages will be deleted automatically by a Cron job.

The run_as_root_clean_old_queue_error_messages cron job is scheduled to run every day at 02:00 AM.


Skipping the retry

In case you have a queue configured for retry but there is some scenario that doesn't need the message to be processed again, just add concatenate the MESSAGE_QUEUE_SKIP_RETRY string in the exception message. With it the message will not enter in the retry loop.


Important note: Make sure to configure the retry limit of your queue with the queue_retry.xml file and enable the message queue retry configuration. If you configure the dead letter exchange and do not do the steps mentioned, the message will be in a retry loop. In other words, it will execute until the consumer processes the message without throwing an exception. This is the default behavior for the RabbitMQ dead letter exchange and will work this way even if this module is not installed.

For more information of how to configure message queues in Magento 2, you can take a look here.


Exploring a real scenario

If you want to know more about this module and explore a real scenario with it, please, take a look at the blog post we wrote about it.


License

MIT


All versions of magento2-message-queue-retry with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
magento/framework Version ~103.0.5
magento/module-backend Version ~102.0.5
magento/module-config Version ~101.2.5
magento/module-ui Version ~101.2.5
php-amqplib/php-amqplib Version ^v3.2.0
magento/framework-amqp Version ~100.4.3
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 run-as-root/magento2-message-queue-retry contains the following files

Loading the files please wait ....