Configure message queues
Any module can be configured to send and receive messages to the message queue. To do this, you must create the following files in the
<module>/etc/communication.xml file defines aspects of the message queue system that all communication types have in common. Magento 2.1 supports AMQP and database connections.
Topic configuration is flexible in that you can switch the transport layer for topics at deployment time. These values can be overwritten in the
name parameter is required. The topic definition must include either a
request or a
schema if you want to implement a custom service interface. Otherwise, specify
request is specified, then also specify
response if the topic is synchronous.
|name||A string that uniquely identifies the topic. A topic name should be a series of strings that are separated by periods. The leftmost string should be the most general, and each string afterward should narrow the scope. For example, to describe actions for tending to pets, you might create names such as
|request||Specifies the data type of the topic.|
|response||Specifies the format of the response. This parameter is required if you are defining a synchronous topic. Omit this parameter if you are defining an asynchronous topic.|
|schema||The interface that describes the structure of the message. The format must be
handler element specifies the class where the logic for handling messages exists and the method it executes.
|name||A string that uniquely defines the handler. The name can be derived from the topic name if the handler is specific to the topic. If the handler provides more generic capabilities, name the handler so that it describes those capabilities.|
|type||The class that defines the handler.|
|method||The method this handler executes.|
|disabled||Determines whether this handler is disabled. The default value is
The following sample defines two synchronous topics. The first topic is for RPC calls. The second uses a custom service interface.
queue.xml file defines the broker that processes topics. It also specifies the queue each topic will be sent to.
broker element also contains
|topic||A topic defined in the
|type||The type of message broker. For this release, the value must be
|exchange||The name of the exchange to publish to. The default system exchange name is
queue element defines the module’s queues.
|name (required)||Defines the queue name to send the message to.|
|consumer (required)||The name of the consumer.|
|consumerInstance||The path to a Magento class that consumes the message.|
|handler||Specifies the class and method that processes the message. The value must be specified in the format
|maxMessages||Specifies the maximum number of messages to consume.|