Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 270817f

Browse files
author
Vasiliev.A
committed
Add support for topic schema defined as ServiceName:methodName
1 parent 57b5fdb commit 270817f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\WebapiAsync\Plugin\Communication\Config;
10+
11+
use Magento\AsynchronousOperations\Model\ConfigInterface;
12+
use Magento\Framework\Communication\ConfigInterface as CommunicationConfig;
13+
14+
class CompositeReader
15+
{
16+
/**
17+
* Topics with type schema is always are sync
18+
* @see \Magento\Framework\Communication\Config\ReflectionGenerator::generateTopicConfigForServiceMethod().
19+
* This plugin add support for topic type schema defined as ServiceName:methodName
20+
* by force changing sync type to async
21+
* but only if topic name starts with ConfigInterface::TOPIC_PREFIX, e.g. async.*
22+
*
23+
* @param \Magento\Framework\Communication\Config\CompositeReader $subject
24+
* @param array $result
25+
*
26+
* @return array
27+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
28+
*/
29+
public function afterRead(\Magento\Framework\Communication\Config\CompositeReader $subject, array $result) {
30+
foreach ($result[CommunicationConfig::TOPICS] as $topicName => $topicConfig) {
31+
if (strpos($topicName, ConfigInterface::DEFAULT_HANDLER_NAME) === 0) {
32+
$topicConfig[CommunicationConfig::TOPIC_IS_SYNCHRONOUS] = false;
33+
$result[CommunicationConfig::TOPICS][$topicName] = $topicConfig;
34+
}
35+
}
36+
return $result;
37+
}
38+
}

app/code/Magento/WebapiAsync/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@
4242
<argument name="processorPath" xsi:type="const">Magento\WebapiAsync\Controller\Rest\AsynchronousSchemaRequestProcessor::BULK_PROCESSOR_PATH</argument>
4343
</arguments>
4444
</virtualType>
45+
<type name="Magento\Framework\Communication\Config\CompositeReader">
46+
<plugin name="forceTopicsTypeToAsync" type="Magento\WebapiAsync\Plugin\Communication\Config\CompositeReader" />
47+
</type>
4548
</config>

0 commit comments

Comments
 (0)