Skip to content

Commit 1caac94

Browse files
committed
AC-14558::Migration form RabbitMQ to Apache ActiveMQ
1 parent 52bd933 commit 1caac94

File tree

7 files changed

+231
-6
lines changed

7 files changed

+231
-6
lines changed

dev/tests/integration/_files/Magento/TestModuleAsyncStomp/Model/CustomHandler.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ class CustomHandler
1212
/**
1313
* @param AsyncTestData $simpleDataItem
1414
*/
15-
public function process(AsyncTestData $simpleDataItem): void
15+
public function process($simpleDataItem): void
1616
{
1717
file_put_contents(
1818
$simpleDataItem->getTextFilePath(),
19-
'custom-string-' . $simpleDataItem->getValue() . PHP_EOL,
19+
'stomp-string-' . $simpleDataItem->getValue() . PHP_EOL,
2020
FILE_APPEND
2121
);
2222
}
2323

2424
/**
2525
* @param AsyncTestData[] $simpleDataItems
2626
*/
27-
public function processArray(array $simpleDataItems): void
27+
public function processArray($simpleDataItems): void
2828
{
2929
foreach ($simpleDataItems as $objItem) {
3030
file_put_contents(
3131
$objItem->getTextFilePath(),
32-
'custom-array-' . $objItem->getValue() . PHP_EOL,
32+
'stomp-array-' . $objItem->getValue() . PHP_EOL,
3333
FILE_APPEND
3434
);
3535
}
@@ -38,7 +38,7 @@ public function processArray(array $simpleDataItems): void
3838
/**
3939
* @param mixed $simpleDataItems
4040
*/
41-
public function processMixed(mixed $simpleDataItems): void
41+
public function processMixed($simpleDataItems): void
4242
{
4343
/** @var AsyncTestData[] $simpleDataItems */
4444
$simpleDataItems = is_array($simpleDataItems) ? $simpleDataItems : [$simpleDataItems];
@@ -53,7 +53,7 @@ public function processMixed(mixed $simpleDataItems): void
5353
}
5454
file_put_contents(
5555
$simpleDataItem->getTextFilePath(),
56-
'custom-mixed-' . $simpleDataItem->getValue() . PHP_EOL,
56+
'stomp-mixed-' . $simpleDataItem->getValue() . PHP_EOL,
5757
FILE_APPEND
5858
);
5959
}

dev/tests/integration/_files/Magento/TestModuleAsyncStomp/etc/communication.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@
1111
<topic name="stomp.segment2.segment3.wildcard" request="Magento\TestModuleAsyncStomp\Model\AsyncTestData"/>
1212
<topic name="no.match.at.all" request="Magento\TestModuleAsyncStomp\Model\AsyncTestData"/>
1313

14+
<!-- Topics for AsyncMultipleTopicsWithEachQueueTest -->
1415
<topic name="stomp.multi.topic.queue.topic.y" request="Magento\TestModuleAsyncStomp\Model\AsyncTestData">
1516
<handler name="stomp.processAsyncReqC" type="Magento\TestModuleAsyncStomp\Model\RequestHandler" method="process"/>
1617
</topic>
1718
<topic name="stomp.multi.topic.queue.topic.z" request="Magento\TestModuleAsyncStomp\Model\AsyncTestData">
1819
<handler name="stomp.processAsyncReqD" type="Magento\TestModuleAsyncStomp\Model\RequestHandler" method="process"/>
1920
</topic>
21+
22+
<!-- Topics for AsyncMultipleHandlersTest -->
23+
<topic name="stomp.mtmh.topic.1" request="Magento\TestModuleAsyncStomp\Model\AsyncTestData">
24+
<handler name="stomp.mtmh.handler.1" type="Magento\TestModuleAsyncStomp\Model\CustomHandler" method="process"/>
25+
</topic>
26+
<topic name="stomp.mtmh.topic.2" request="Magento\TestModuleAsyncStomp\Model\AsyncTestData[]">
27+
<handler name="stomp.mtmh.handler.2" type="Magento\TestModuleAsyncStomp\Model\CustomHandler" method="processArray"/>
28+
</topic>
2029
</config>

dev/tests/integration/_files/Magento/TestModuleAsyncStomp/etc/queue_consumer.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
<consumer name="stomp.wildcard.queue.one.consumer" connection="stomp" queue="stomp.wildcard.queue.one" handler="Magento\TestModuleAsyncStomp\Model\WildCardHandler::methodOne"/>
1212
<consumer name="stomp.wildcard.queue.two.consumer" connection="stomp" queue="stomp.wildcard.queue.two" handler="Magento\TestModuleAsyncStomp\Model\WildCardHandler::methodTwo"/>
1313

14+
<!-- Consumers for AsyncMultipleTopicsWithEachQueueTest -->
1415
<consumer name="stomp.queue.for.multiple.topics.test.y" queue="stomp.queue.for.multiple.topics.test.y" connection="stomp"/>
1516
<consumer name="stomp.queue.for.multiple.topics.test.z" queue="stomp.queue.for.multiple.topics.test.z" connection="stomp"/>
17+
18+
<!-- Consumers for AsyncMultipleHandlersTest -->
19+
<consumer name="stomp.mtmh.queue.1.consumer" queue="stomp.mtmh.queue.1" connection="stomp"/>
20+
<consumer name="stomp.mtmh.queue.2.consumer" queue="stomp.mtmh.queue.2" connection="stomp"/>
1621
</config>

dev/tests/integration/_files/Magento/TestModuleAsyncStomp/etc/queue_publisher.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@
1919
<connection name="stomp" exchange="magento" />
2020
</publisher>
2121

22+
<!-- Publishers for AsyncMultipleTopicsWithEachQueueTest -->
2223
<publisher topic="stomp.multi.topic.queue.topic.y" queue="stomp.queue.for.multiple.topics.test.y">
2324
<connection name="stomp" exchange="magento" />
2425
</publisher>
2526
<publisher topic="stomp.multi.topic.queue.topic.z" queue="stomp.queue.for.multiple.topics.test.z">
2627
<connection name="stomp" exchange="magento" />
2728
</publisher>
29+
30+
<!-- Publishers for AsyncMultipleHandlersTest -->
31+
<publisher topic="stomp.mtmh.topic.1" queue="stomp.mtmh.queue.1">
32+
<connection name="stomp" exchange="magento" />
33+
</publisher>
34+
<publisher topic="stomp.mtmh.topic.2" queue="stomp.mtmh.queue.2">
35+
<connection name="stomp" exchange="magento" />
36+
</publisher>
2837
</config>

dev/tests/integration/_files/Magento/TestModuleAsyncStomp/etc/queue_topology.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
99
<exchange name="magento" connection="stomp" type="topic">
1010
<binding id="stomp.async.binding1" topic="stomp.multi.topic.queue.topic.c" destinationType="queue" destination="stomp.mixed.sync.and.async.queue"/>
11+
12+
<!-- Bindings for AsyncMultipleTopicsWithEachQueueTest - STOMP one-to-one mapping -->
1113
<binding id="stomp.async.binding8" topic="stomp.multi.topic.queue.topic.y" destinationType="queue" destination="stomp.queue.for.multiple.topics.test.y"/>
1214
<binding id="stomp.async.binding9" topic="stomp.multi.topic.queue.topic.z" destinationType="queue" destination="stomp.queue.for.multiple.topics.test.z"/>
15+
16+
<!-- Bindings for AsyncMultipleHandlersTest - STOMP one-to-one mapping -->
17+
<binding id="stomp.async.binding.mtmh.1" topic="stomp.mtmh.topic.1" destinationType="queue" destination="stomp.mtmh.queue.1"/>
18+
<binding id="stomp.async.binding.mtmh.2" topic="stomp.mtmh.topic.2" destinationType="queue" destination="stomp.mtmh.queue.2"/>
1319
</exchange>
1420
</config>
1521

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Stomp\UseCase;
9+
10+
use Magento\Framework\MessageQueue\DefaultValueProvider;
11+
use Magento\Framework\MessageQueue\UseCase\QueueTestCaseAbstract;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestModuleAsyncStomp\Model\AsyncTestData;
14+
15+
class AsyncMultipleHandlersTest extends QueueTestCaseAbstract
16+
{
17+
/**
18+
* @var string
19+
*/
20+
protected $expectedMessages;
21+
22+
/**
23+
* @var string[]
24+
*/
25+
protected $consumers = [
26+
'stomp.mtmh.queue.1.consumer',
27+
'stomp.mtmh.queue.2.consumer',
28+
];
29+
30+
/**
31+
* @var string[]
32+
*/
33+
private $topicValueMap = [
34+
'stomp.mtmh.topic.1' => 'stomp.mtmh.topic.1',
35+
'stomp.mtmh.topic.2' => ['stomp.mtmh.topic.2-1', 'stomp.mtmh.topic.2-2']
36+
];
37+
38+
/**
39+
* @var string[]
40+
*/
41+
private $expectedValues = [
42+
'stomp-string-stomp.mtmh.topic.1',
43+
'stomp-array-stomp.mtmh.topic.2-1',
44+
'stomp-array-stomp.mtmh.topic.2-2'
45+
];
46+
47+
/**
48+
* @var string
49+
*/
50+
private $connectionType;
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
protected function setUp(): void
56+
{
57+
$this->objectManager = Bootstrap::getObjectManager();
58+
/** @var DefaultValueProvider $defaultValueProvider */
59+
$defaultValueProvider = $this->objectManager->get(DefaultValueProvider::class);
60+
$this->connectionType = $defaultValueProvider->getConnection();
61+
62+
if ($this->connectionType === 'stomp') {
63+
parent::setUp();
64+
}
65+
}
66+
67+
/**
68+
* Verify that Queue Framework supports multiple handlers with STOMP's one-to-one topic-queue architecture.
69+
*
70+
* Unlike AMQP's many-to-many model, STOMP uses dedicated queues for each topic.
71+
* This test verifies that each topic is processed by its own dedicated handler in STOMP.
72+
*
73+
* Current test is not test of Web API framework itself,
74+
* it just utilizes its infrastructure to test Message Queue.
75+
*/
76+
public function testAsynchronousMultipleHandlers()
77+
{
78+
if ($this->connectionType === 'amqp') {
79+
$this->markTestSkipped('STOMP test skipped because AMQP connection is available.
80+
This test is STOMP-specific.');
81+
}
82+
83+
foreach ($this->topicValueMap as $topic => $data) {
84+
$message = null;
85+
if (is_array($data)) {
86+
foreach ($data as $key => $value) {
87+
/** @var AsyncTestData $testObject */
88+
$testObject = $this->objectManager->create(AsyncTestData::class); // @phpstan-ignore-line
89+
$testObject->setValue($value);
90+
$testObject->setTextFilePath($this->logFilePath);
91+
$message[$key] = $testObject;
92+
}
93+
} else {
94+
$testObject = $this->objectManager->create(AsyncTestData::class); // @phpstan-ignore-line
95+
$testObject->setValue($data);
96+
$testObject->setTextFilePath($this->logFilePath);
97+
$message = $testObject;
98+
}
99+
$this->publisher->publish($topic, $message);
100+
}
101+
102+
$this->waitForAsynchronousResult(count($this->expectedValues), $this->logFilePath);
103+
104+
//assertions
105+
foreach ($this->expectedValues as $item) {
106+
$this->assertStringContainsString($item, file_get_contents($this->logFilePath));
107+
}
108+
}
109+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
namespace Magento\Framework\Stomp\UseCase;
7+
8+
use Magento\Framework\MessageQueue\DefaultValueProvider;
9+
use Magento\Framework\MessageQueue\UseCase\QueueTestCaseAbstract;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\TestModuleAsyncStomp\Model\AsyncTestData;
12+
13+
class AsyncMultipleTopicsWithEachQueueTest extends QueueTestCaseAbstract
14+
{
15+
/**
16+
* @var string[]
17+
*/
18+
protected $uniqueID;
19+
20+
/**
21+
* @var AsyncTestData
22+
*/
23+
protected $msgObject;
24+
25+
/**
26+
* @var string[]
27+
*/
28+
protected $consumers = ['stomp.queue.for.multiple.topics.test.y', 'stomp.queue.for.multiple.topics.test.z'];
29+
30+
/**
31+
* @var string[]
32+
*/
33+
private $topics = ['stomp.multi.topic.queue.topic.y', 'stomp.multi.topic.queue.topic.z'];
34+
35+
/**
36+
* @var string
37+
*/
38+
private $connectionType;
39+
40+
/**
41+
* @inheritdoc
42+
*/
43+
protected function setUp(): void
44+
{
45+
$this->objectManager = Bootstrap::getObjectManager();
46+
/** @var DefaultValueProvider $defaultValueProvider */
47+
$defaultValueProvider = $this->objectManager->get(DefaultValueProvider::class);
48+
$this->connectionType = $defaultValueProvider->getConnection();
49+
50+
if ($this->connectionType === 'stomp') {
51+
parent::setUp();
52+
}
53+
}
54+
55+
/**
56+
* Verify that Queue Framework processes multiple asynchronous topics sent to the same queue.
57+
*
58+
* Current test is not test of Web API framework itself, it just utilizes its infrastructure to test Message Queue.
59+
*/
60+
public function testAsyncMultipleTopicsPerQueue()
61+
{
62+
if ($this->connectionType === 'amqp') {
63+
$this->markTestSkipped('STOMP test skipped because AMQP connection is available.
64+
This test is STOMP-specific.');
65+
}
66+
67+
$this->msgObject = $this->objectManager->create(AsyncTestData::class); // @phpstan-ignore-line
68+
69+
foreach ($this->topics as $topic) {
70+
// phpcs:ignore Magento2.Security.InsecureFunction
71+
$this->uniqueID[$topic] = md5(uniqid($topic));
72+
$this->msgObject->setValue($this->uniqueID[$topic] . "_" . $topic);
73+
$this->msgObject->setTextFilePath($this->logFilePath);
74+
$this->publisher->publish($topic, $this->msgObject);
75+
}
76+
77+
$this->waitForAsynchronousResult(count($this->uniqueID), $this->logFilePath);
78+
79+
//assertions
80+
foreach ($this->topics as $item) {
81+
$this->assertStringContainsString(
82+
$this->uniqueID[$item] . "_" . $item,
83+
file_get_contents($this->logFilePath)
84+
);
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)