Important
You are browsing documentation for version 5.1 of OroCommerce, supported until March 2027. Read the documentation for the latest LTS version to get up-to-date information.
See our Release Process documentation for more information on the currently supported and upcoming releases.
Re-deliver Message with Limited Attempts
Procedure
Example
The example below illustrates how to configure message re-delivery with limited attempts. You can use this flow both with the out-of-the-box configuration, and with Multiple Queue Dividing. Use the commands provided by the RabbitMQ management plugin.
Create oro.unprocessed Queue
Create an oro.unprocessed queue to store messages that failed more than the maximum available attempts.
rabbitmqadmin declare queue --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST \
name="oro.unprocessed" durable=true arguments='{"x-max-priority": 4}'
Re-Declare oro.default.delayed Exchange
Re-declare the oro.default.delayed exchange to make sure it is declared and has no additional bindings.
rabbitmqadmin delete exchange --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST \
name="oro.default.delayed"
rabbitmqadmin declare exchange --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST \
name="oro.default.delayed" type="x-delayed-message" \
durable=true arguments='{"x-delayed-type": "fanout"}'
Declare oro.redelivery.control Exchange
After a delay timeout, re-delivered messages pass to the oro.default.delayed exchange, which routes them to oro.redelivery.control to check the number of redelivered attempts.
rabbitmqadmin declare exchange --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST \
name="oro.redelivery.control" type="headers" durable=true \
arguments='{"alternate-exchange": "oro.default"}'
rabbitmqadmin declare binding --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST \
source="oro.default.delayed" destination="oro.redelivery.control" destination_type="exchange"
Configure Count of Re-Delivery Attempts
Set the maximum number of message re-delivery attempts. The example below uses 5.
rabbitmqadmin declare binding --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST \
source="oro.redelivery.control" destination="oro.unprocessed" destination_type="queue" \
arguments='{"oro-redeliver-count": 5}'
What Next?
From time to time, collect metrics on how many messages there are in the oro.unprocessed queue.
If the number of messages grows, check the application logs and fix the problem manually.
Once you fix a problem, route the messages back to the oro.default exchange using the RabbitMQ Shovel Plugin.
Possible Problems
If you applied the current configuration to an application that had been in production for some time,
some messages can contain headers with oro-redeliver-count more than 5.
In this case, manually check the message redelivery count:
rabbitmqadmin get queue="oro.default" --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST
In addition, declare an additional binding for the oro.redelivery.control exchange. For example, if oro-redeliver-count equals 153, then:
rabbitmqadmin declare binding --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST \
source="oro.redelivery.control" destination="oro.unprocessed" destination_type=queue \
arguments='{"oro-redeliver-count": 154}' routing_key="additional_binding"
Once the failed message is caught, remove additional binding:
# get properties key for additional binding
rabbitmqadmin list bindings --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST \
source destination routing_key properties_key | grep "properties_key\|additional_binding"
rabbitmqadmin delete binding --host=$HOST --user=$USER --password=$PASSWORD --vhost=$VHOST \
source="oro.redelivery.control" destination="oro.unprocessed" destination_type=queue \
properties_key='additional_binding~UFQ6EQ'
For more information, see the following external resources: