Edit in GitHubLog an issue
Thanks to comwrap GmbH for contributing this topic!

Topics in asynchronous API

The message queue system uses "topic exchange" for managing messages. More information about topics can be found here.

Topics are usually defined in a communication.xml configuration file. See Configure message queues

Generating of communication.xml#

A communication.xml is pre-generated automatically by the WebapiAsync module. This module also generates topic names for asynchronous processes. Generated files are processed by the \Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader\Communication class, which implements \Magento\Framework\Config\ReaderInterface and is injected into \Magento\Framework\Communication\Config\CompositeReader as a constructor argument of the main di.xml file.

Copied to your clipboard
1<type name="Magento\Framework\Communication\Config\CompositeReader">
2 <arguments>
3 <argument name="readers" xsi:type="array">
4 <item name="asyncServiceReader" xsi:type="array">
5 <item name="reader" xsi:type="object">Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader\Communication</item>
6 <item name="sortOrder" xsi:type="string">0</item>
7 </item>
8 <item name="xmlReader" xsi:type="array"> ... </item>
9 ...
10 </argument>
11 </arguments>
12</type>

Sort order is set to 0 by default. This allows developers to change some aspects of the generated configuration in configuration readers, such as communication.xml, env.php.

\Magento\Framework\Communication\Config\CompositeReader::read() collects configuration records from defined readers and merges these records into a single configurataion.

Because the generation of thge topics configuration is based on schema type, the generated <topic> XML is returned with "sync"=true. The response attribut is based on the service response definition. So the WebapiAsync module changes those settings to "sync"=false and response is set to null. These changes will allow the application to execute topics asynchronously.

Topics generation#

Asynchronous and Bulk APIs are built on top of the standard Rest API. Topics for message processing fo asynchronous and bulk APIs are generated automatically, together with the communication.xml schema. This is done by \Magento\WebapiAsync\Model\Config::getServices(). The current method is responsible for retrieving all service contracts defined in webapi.xml files and generates topic names for the corresponding asynchronous requests.

generateTopicNameFromService($serviceInterface, $serviceMethod, $httpMethod) is responsible for generating a topic name based on the service contract interface, the service contract method, and the HTTP method.

As example, the route defined in webapi.xml:

Copied to your clipboard
1<route url="/V1/products" method="POST">
2 <service class="Magento\Catalog\Api\ProductRepositoryInterface" method="save"/>
3 <resources>
4 <resource ref="Magento_Catalog::products" />
5 </resources>
6</route>

will generate the following topic name:

async.magento.catalog.api.productrepositoryinterface.save.post.

It consists of following parts:

  • "async." as a prefix
  • lower cased service class
  • lower cased service method
  • lover cased http method

Unfortunately, there are no easy way to get a list of all generated topic names, but knowing this pattern, developers can find the required topic name and use it for executing service contracts in asynchronously.

Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.