Skip to content

I. How Async Events Work

Gowri edited this page Dec 9, 2021 · 8 revisions

Asynchronous events are defined in an async_events.xml. This is similar to defining regular events with events.xml. An asynchronous event can have many subscribers which listen to it and get notified when the event is dispatched.

Philosophy

How It Works

The above image describes the logical flow of a single asynchronous event dispatched to three subscribers. The event is dispatched from Magento and placed on a queue. Then it is picked up by a consumer that is responsible to dispatch the notifications to the subscribers in a way intended for them.

For example, subscriber 1 might want to be notified via REST, subscriber 2 via SOAP and subscriber 3 via gRPC.

Example Async Event

<async_event name="sales.order.created">
    <service class="Magento\Sales\Api\OrderRepositoryInterface" method="get"/>
</async_event>

The above code defines an async_event named sales.order.created and when it is dispatched to its subscribers it will have the payload which is the return value of Magento\Sales\Api\OrderRepositoryInterface::get

Clone this wiki locally