-
Notifications
You must be signed in to change notification settings - Fork 4
Using DB Queues
Gowri edited this page Dec 10, 2021
·
4 revisions
If you're unable to use RabbitMQ, it is possible to use database queues instead. However there are somethings that require more manual control such as exponential backed off retries and dead letters.
Since Magento provides an abstraction over message brokers using the MessageQueue
framework, it is possible to override and swap RabbitMQ Queues to Database Queues.
To get started, create a new module in your app/code
.
This wiki assumes the new module will be YourVendorName/AsyncEvents
.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="YourVendorName/AsyncEvents">
<sequence>
<module name="Aligent_AsyncEvents"/>
</sequence>
</module>
</config>
Under YourVendorName/AsyncEvents/etc
, create and add the following files.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/consumer.xsd">
<consumer name="event.trigger.consumer" queue="event.trigger" connection="db"
consumerInstance="Magento\Framework\MessageQueue\Consumer"
handler="Aligent\AsyncEvents\Model\AsyncEventTriggerHandler::process" />
<consumer name="event.retry.consumer" queue="event.failover.retry" connection="db"
consumerInstance="Magento\Framework\MessageQueue\Consumer" />
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/publisher.xsd">
<publisher topic="event.trigger">
<connection name="db" exchange="magento-db"/>
</publisher>
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
<exchange name="magento" type="topic" connection="db">
<binding id="event.trigger" topic="event.trigger" destinationType="queue" destination="event.trigger"/>
</exchange>
<exchange name="event.failover" type="topic" connection="db">
<binding id="EventFailoverRetry" topic="event.retry" destinationType="queue" destination="event.failover.retry"/>
<binding id="EventKillerBinding" topic="event.retry.kill" destinationType="queue" destination="event.failover.deadletter"/>
</exchange>
</config>