lib/internal/Magento/Framework/Stomp/README.md
This implementation provides seamless support for both RabbitMQ (AMQP) and Apache ActiveMQ Artemis (STOMP) message queues. The system automatically routes messages based on connection configuration.
<?php
return [
// ... other config
'queue' => [
// Default AMQP (RabbitMQ) connection
'amqp' => [
'host' => 'localhost',
'port' => 5672,
'user' => 'guest',
'password' => 'guest',
'virtualhost' => '/'
],
// STOMP (ActiveMQ Artemis) connections
'stomp' => [
'host' => 'localhost',
'port' => 61613,
'user' => 'artemis',
'password' => 'artemis',
'ssl' => false,
'ssl_options' => [],
// Performance tuning options
'heartbeat_send' => 10000, // 10 seconds
'heartbeat_receive' => 10000, // 10 seconds
'read_timeout' => 250000 // 250ms
],
// Multiple STOMP connections for different purposes
'connections' => [
'inventory_stomp' => [
'host' => 'inventory-queue.example.com',
'port' => 61613,
'user' => 'inventory_user',
'password' => 'inventory_pass',
'ssl' => true,
'ssl_options' => [
'verify_peer' => false,
'verify_peer_name' => false
]
],
'catalog_stomp' => [
'host' => 'catalog-queue.example.com',
'port' => 61613,
'user' => 'catalog_user',
'password' => 'catalog_pass'
]
]
]
];
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
<!-- RabbitMQ exchanges -->
<exchange name="magento.catalog" type="topic" connection="amqp">
<binding id="catalogBinding" topic="catalog.*" destinationType="queue" destination="catalog.updates"/>
</exchange>
<!-- ActiveMQ exchanges -->
<exchange name="magento.inventory" type="topic" connection="stomp">
<binding id="inventoryBinding" topic="inventory.*" destinationType="queue" destination="inventory.updates"/>
</exchange>
<!-- Multiple connection support -->
<exchange name="magento.catalog.special" type="topic" connection="catalog_stomp">
<binding id="catalogSpecialBinding" topic="catalog.special.*" destinationType="queue" destination="catalog.special.updates"/>
</exchange>
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/consumer.xsd">
<!-- RabbitMQ consumers -->
<consumer name="catalog.updates" queue="catalog.updates" connection="amqp"
handler="Magento\Catalog\Model\MessageQueue\UpdateHandler::execute"/>
<!-- ActiveMQ consumers -->
<consumer name="inventory.updates" queue="inventory.updates" connection="stomp"
handler="Magento\Inventory\Model\MessageQueue\UpdateHandler::execute"/>
<!-- Multiple connection consumers -->
<consumer name="catalog.special.updates" queue="catalog.special.updates" connection="catalog_stomp"
handler="Magento\Catalog\Model\MessageQueue\SpecialUpdateHandler::execute"/>
</config>
The system automatically determines the connection type:
amqp or not found in STOMP configurationstomp or found in queue.connections arrayThe enhanced StompClient provides robust error handling:
// Retryable error patterns
- 'connection' issues
- 'write frame' errors
- 'broken pipe'
- 'network' timeouts
- 'AMQ229014' (ActiveMQ specific)
- 'AMQ229031' (Connection lost)
- 'disconnected' states
- 'socket' errors
// env.php optimizations
'stomp' => [
'host' => 'localhost',
'port' => 61613,
'user' => 'artemis',
'password' => 'artemis',
// Reduce heartbeat for high-frequency operations
'heartbeat_send' => 5000, // 5 seconds
'heartbeat_receive' => 5000, // 5 seconds
// Adjust read timeout for responsiveness
'read_timeout' => 100000 // 100ms
]
The system provides two clearing mechanisms:
Causes:
Solutions:
# Check ActiveMQ status
systemctl status activemq-artemis
# Verify network connectivity
telnet localhost 61613
# Check queue permissions in ActiveMQ console
http://localhost:8161/console
Error: Unknown connection name 'stomp'
Solution: Ensure proper configuration in env.php:
'queue' => [
'stomp' => [
'host' => 'localhost',
// ... other config
]
]
Solution: Configure SSL options:
'stomp' => [
'ssl' => true,
'ssl_options' => [
'verify_peer' => false,
'verify_peer_name' => false,
'cafile' => '/path/to/ca.pem'
]
]
Enable debug logging:
// Add to env.php
'log' => [
'channel' => [
'message_queue' => [
'handlers' => [
'debug' => [
'type' => 'stream',
'path' => '/var/log/magento/message_queue.log',
'level' => 'debug'
]
]
]
]
]
# RabbitMQ
rabbitmqctl status
# ActiveMQ Artemis
curl -u admin:admin http://localhost:8161/console/jolokia/read/org.apache.activemq.artemis:broker="0.0.0.0"/Started
# View queue depth
curl -u admin:admin "http://localhost:8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"0.0.0.0\",component=addresses,address=\"your.queue\",subcomponent=queues,routing-type=\"anycast\",queue=\"your.queue\"/MessageCount"