Skip to content

Commit 9580cd2

Browse files
Merge pull request #410 from djadobe16/AC-15629
Adobe Development Doc - Message Queues - ActiveMq (Artemis) updates
2 parents 10e31ec + 9d2dc2e commit 9580cd2

File tree

3 files changed

+85
-13
lines changed

3 files changed

+85
-13
lines changed

src/pages/development/components/message-queues/async-configuration.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,36 @@ The `queue_publisher.xml` file is generated by the `\Magento\WebapiAsync\Code\Ge
4646

4747
The sort order is set to 0 and allows developers to change some aspects of the generated configuration in configuration readers such as `queue_publisher.xml` and `env.php`.
4848

49-
`\Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader\Publisher::read()` calls `\Magento\AsynchronousOperations\Model\ConfigInterface::getServices()` to get an array of all REST API routes which can be executed asynchronously. Then it defines the connection name as `amqp` and the exchange as `magento` for each generated topic name.
49+
`\Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader\Publisher::read()` calls `\Magento\AsynchronousOperations\Model\ConfigInterface::getServices()` to get an array of all REST API routes which can be executed asynchronously. Then it defines the connection name as `amqp` (or `stomp` for ActiveMQ Artemis) and the exchange as `magento` for each generated topic name.
5050

5151
## queue_consumer.xml
5252

5353
The asynchronous/bulk API has one defined consumer which processes all asynchronous/bulk APIs messages.
5454

5555
```xml
56-
<consumer name="async.operations.all" queue="async.operations.all" connection="amqp"
56+
<consumer name="async.operations.all" queue="async.operations.all"
5757
consumerInstance="Magento\AsynchronousOperations\Model\MassConsumer"/>
5858
```
5959

60+
The connection type (AMQP or STOMP) is determined automatically based on your `env.php` configuration.
61+
6062
### queue_topology.xml
6163

6264
The message queue topology configuration links all auto-generated topic names with prefix `async.` to the `magento` exchange and defines the queue named `async.operations.all` as the destination for all messages.
6365

6466
```xml
65-
<exchange name="magento" connection="amqp">
67+
<exchange name="magento">
6668
<binding id="async.operations.all" topic="async.#" destination="async.operations.all"/>
6769
</exchange>
6870
```
6971

72+
The connection type is automatically determined from your `env.php` configuration.
73+
74+
<InlineAlert variant="info" slots="text"/>
75+
76+
Message queues connection is defined dynamically based on deployment configuration in `env.php`. If AMQP or STOMP is configured in deployment configuration of the queue, the respective connection is used. Otherwise, db connection is used.
77+
As a result, if AMQP or STOMP is configured in deployment configuration of the queue, connection declaration can be omitted in [message queue configuration files](./configuration.md): `queue_customer.xml`, `queue_publisher.xml`, `queue_topology.xml`.
78+
7079
<InlineAlert variant="info" slots="text"/>
7180

72-
Message queues connection is defined dynamically based on deployment configuration in `env.php`. If AMQP is configured in deployment configuration of the queue, AMQP connection is used. Otherwise, db connection is used.
73-
As a result, if AMQP is configured in deployment configuration of the queue, connection declaration can be omitted in [message queue configuration files](./configuration.md): `queue_customer.xml`, `queue_publisher.xml`, `queue_topology.xml`.
81+
ActiveMQ Artemis (STOMP) was introduced in Adobe Commerce 2.4.6 and later versions. For STOMP connections, use ANYCAST addressing mode for point-to-point message delivery and load balancing across multiple consumers.

src/pages/development/components/message-queues/bulk-operations-example.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,35 +319,55 @@ The `queue_consumer.xml` file defines the relationship between a queue and its c
319319

320320
```xml
321321
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/consumer.xsd">
322-
<consumer name="<consumer_name>" queue="<queue_name>" connection="amqp" consumerInstance="Magento\Framework\MessageQueue\Consumer" handler="<Consumer_Class>::<Consumer_method>"/>
322+
<consumer name="<consumer_name>" queue="<queue_name>" consumerInstance="Magento\Framework\MessageQueue\Consumer" handler="<Consumer_Class>::<Consumer_method>"/>
323323
</config>
324324
```
325325

326+
The connection type (AMQP or STOMP) is determined automatically based on your `env.php` configuration.
327+
326328
### Create `queue_publisher.xml`
327329

328330
The `queue_publisher.xml` file defines the exchange where a topic is published. Create this file with the following contents:
329331

332+
**For RabbitMQ (AMQP):**
333+
330334
```xml
331335
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/publisher.xsd">
332336
<publisher topic="<topic_name>">
333-
<connection name="amqp" exchange="<exchange>" />
337+
<connection exchange="<exchange>" />
334338
</publisher>
335339
</config>
336340
```
337341

342+
**For ActiveMQ Artemis (STOMP):**
343+
344+
```xml
345+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/publisher.xsd">
346+
<publisher topic="<topic_name>" queue="<queue_name>" />
347+
</config>
348+
```
349+
350+
**Note**: For ActiveMQ Artemis, the `<connection>` element is not required as the connection type is determined from `env.php`. When the topic name and queue name are different, you must specify the `queue` attribute in the `<publisher>` element.
351+
338352
### Create `queue_topology.xml`
339353

340354
The `queue_topology.xml` file defines the message routing rules and declares queues and exchanges. Create this file with the following contents:
341355

342356
```xml
343357
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
344-
<exchange name="magento" type="topic" connection="amqp">
358+
<exchange name="magento" type="topic">
345359
<binding id="defaultBinding" topic="" destinationType="queue" destination="<queue_name>"/>
346360
</exchange>
347361
</config>
348362
```
349363

364+
The connection type is automatically determined from your `env.php` configuration.
365+
366+
<InlineAlert variant="info" slots="text"/>
367+
368+
Message queue connections are defined dynamically, based on the deployment configuration in the `env.php` file. If AMQP or STOMP is configured in the deployment configuration of the queue, the respective connection is used. Otherwise, database connections are used.
369+
As a result, if AMQP or STOMP is configured in the deployment configuration of the queue, you can omit connection declarations in the `queue_consumer.xml`, `queue_publisher.xml`, and `queue_topology.xml` [message queue configuration files](./configuration.md).
370+
350371
<InlineAlert variant="info" slots="text"/>
351372

352-
Message queue connections are defined dynamically, based on the deployment configuration in the `env.php` file. If AMQP is configured in the deployment configuration of the queue, AMQP connections are used. Otherwise, database connections are used.
353-
As a result, if AMQP is configured in the deployment configuration of the queue, you can omit connection declarations in the `queue_consumer.xml`, `queue_publisher.xml`, and `queue_topology.xml` [message queue configuration files](./configuration.md).
373+
ActiveMQ Artemis (STOMP) was introduced in Adobe Commerce 2.4.6 and later versions. For STOMP connections, use ANYCAST addressing mode for point-to-point message delivery and load balancing across multiple consumers.

src/pages/development/components/message-queues/index.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ keywords:
99

1010
Message queues provide an asynchronous communications mechanism in which the sender and the receiver of a message do not contact each other, nor do they need to communicate with the message queue at the same time. When a sender places a message onto a queue, it is stored until the recipient receives them.
1111

12-
In Adobe Commerce and Magento Open Source, the Message Queue Framework (MQF) is a fully-functional system that allows a module to publish messages to queues. It also creates consumers to receive them asynchronously. The MQF primarily uses [RabbitMQ](http://www.rabbitmq.com) as the messaging broker, which provides a scalable platform for sending and receiving messages. It also includes a mechanism for storing undelivered messages. RabbitMQ is based on the Advanced Message Queuing Protocol (AMQP) 0.9.1 specification.
12+
In Adobe Commerce and Magento Open Source, the Message Queue Framework (MQF) is a fully-functional system that allows a module to publish messages to queues. It also creates consumers to receive them asynchronously. The MQF supports multiple messaging brokers:
1313

14-
A basic message queue system can also be set up without using RabbitMQ. In this system, a MySQL adapter stores messages in the database. Three database tables (`queue`, `queue_message`, and `queue_message_status`) manage the message queue workload. Cron jobs ensure the consumers are able to receive messages. This solution is not very scalable. RabbitMQ should be used whenever possible.
14+
- **[RabbitMQ](http://www.rabbitmq.com)** - The primary messaging broker, which provides a scalable platform for sending and receiving messages. It includes a mechanism for storing undelivered messages and is based on the Advanced Message Queuing Protocol (AMQP) 0.9.1 specification.
15+
- **[Apache ActiveMQ Artemis](https://activemq.apache.org/components/artemis/)** - An alternative messaging broker that uses the STOMP (Simple Text Oriented Messaging Protocol) for reliable and scalable messaging, offering flexibility for STOMP-based integrations.
16+
17+
A basic message queue system can also be set up without using external message brokers. In this system, a MySQL adapter stores messages in the database. Three database tables (`queue`, `queue_message`, and `queue_message_status`) manage the message queue workload. Cron jobs ensure the consumers are able to receive messages. This solution is not very scalable. External message brokers like RabbitMQ or ActiveMQ Artemis should be used whenever possible.
1518

1619
See [Configure message queues](configuration.md) for information about setting up the message queue system.
1720

@@ -49,7 +52,11 @@ Perform the following actions:
4952
1. Decode the message using topic name taken from the `\Magento\Framework\MessageQueue\ConsumerConfigurationInterface`.
5053
1. Invoke callback `Magento\Framework\MessageQueue\ConsumerConfigurationInterface::getCallback` and pass the decoded data as an argument.
5154

52-
## Change message queue from MySQL to AMQP
55+
### ActiveMQ Artemis (STOMP)
56+
57+
Similar to RabbitMQ, ActiveMQ Artemis instantiates a consumer that is defined in a [`queue_consumer.xml`](configuration.md#queue_consumerxml) file. The consumer (`customer_created_listener`) listens to the queue and receives all new messages. For every message, it invokes `Magento\Some\Class::processMessage($message)`
58+
59+
## Change message queue from MySQL to external brokers
5360

5461
The following sample introduces a runtime configuration that allows you to redefine the adapter for a topic.
5562

@@ -85,3 +92,40 @@ The following sample introduces a runtime configuration that allows you to redef
8592
],
8693
],
8794
```
95+
96+
### Switch from MySQL to STOMP (ActiveMQ Artemis)
97+
98+
The following configuration shows how to configure a topic to use STOMP instead of MySQL:
99+
100+
```php
101+
'queue' => [
102+
'topics' => [
103+
'inventory.update' => [
104+
'publisher' => 'stomp-magento'
105+
]
106+
],
107+
'config' => [
108+
'publishers' => [
109+
'inventory.update' => [
110+
'connections' => [
111+
'stomp' => [
112+
'name' => 'stomp',
113+
'exchange' => 'magento',
114+
'disabled' => false
115+
],
116+
'db' => [
117+
'name' => 'db',
118+
'exchange' => 'magento',
119+
'disabled' => true
120+
]
121+
]
122+
]
123+
]
124+
],
125+
'consumers' => [
126+
'inventory.update' => [
127+
'connection' => 'stomp',
128+
],
129+
]
130+
],
131+
```

0 commit comments

Comments
 (0)