Skip to content

Commit c0a3d59

Browse files
committed
B2B-2171: Enable WebapiAsync work with redis connection
1 parent 4645beb commit c0a3d59

File tree

7 files changed

+147
-26
lines changed

7 files changed

+147
-26
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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\Code\Generator\Config\RemoteServiceReader;
10+
11+
use Magento\AsynchronousOperations\Model\ConfigInterface as WebApiAsyncConfig;
12+
13+
/**
14+
* Remote service reader with auto generated configuration for queue_consumer.xml
15+
*/
16+
class Consumer implements \Magento\Framework\Config\ReaderInterface
17+
{
18+
/**
19+
* Generate consumer configuration based on remote services declarations
20+
*
21+
* @param string|null $scope
22+
* @return array
23+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
24+
*/
25+
public function read($scope = null)
26+
{
27+
$result = [];
28+
$topicName = 'async.operations.all';
29+
$result[$topicName] =
30+
[
31+
'name' => $topicName,
32+
'queue' => $topicName,
33+
'consumerInstance' => WebApiAsyncConfig::DEFAULT_CONSUMER_INSTANCE,
34+
'connection' => WebApiAsyncConfig::DEFAULT_CONSUMER_CONNECTION,
35+
'maxMessages' => WebApiAsyncConfig::DEFAULT_CONSUMER_MAX_MESSAGE,
36+
'handlers' => [],
37+
'maxIdleTime' => null,
38+
'sleep' => null,
39+
'onlySpawnWhenMessageAvailable' => null
40+
];
41+
42+
return $result;
43+
}
44+
}

app/code/Magento/WebapiAsync/Code/Generator/Config/RemoteServiceReader/Publisher.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public function read($scope = null)
6060
'topic' => $topicName,
6161
'disabled' => false,
6262
'connections' => [
63-
$this->defaultValueProvider->getConnection() => [
64-
'name' => $this->defaultValueProvider->getConnection(),
63+
$this->getConnection() => [
64+
'name' => $this->getConnection(),
6565
'exchange' => 'magento',
6666
'disabled' => false,
6767
],
@@ -71,4 +71,16 @@ public function read($scope = null)
7171

7272
return $result;
7373
}
74+
75+
/**
76+
* Get connection
77+
*
78+
* @return string
79+
*/
80+
private function getConnection()
81+
{
82+
$connection = $this->defaultValueProvider->getConnection();
83+
// if db connection, return amqp instead.
84+
return $connection === 'db' ? WebApiAsyncConfig::DEFAULT_CONSUMER_CONNECTION : $connection;
85+
}
7486
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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\Code\Generator\Config\RemoteServiceReader;
10+
11+
use Magento\AsynchronousOperations\Model\ConfigInterface as WebApiAsyncConfig;
12+
use Magento\Framework\MessageQueue\DefaultValueProvider;
13+
14+
/**
15+
* Remote service reader with auto generated configuration for queue_topology.xml
16+
*/
17+
class Topology implements \Magento\Framework\Config\ReaderInterface
18+
{
19+
/**
20+
* @var DefaultValueProvider
21+
*/
22+
private $defaultValueProvider;
23+
24+
/**
25+
* @param DefaultValueProvider $defaultValueProvider
26+
*/
27+
public function __construct(
28+
DefaultValueProvider $defaultValueProvider
29+
) {
30+
$this->defaultValueProvider = $defaultValueProvider;
31+
}
32+
33+
/**
34+
* Generate topology configuration based on remote services declarations
35+
*
36+
* @param string|null $scope
37+
* @return array
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
39+
*/
40+
public function read($scope = null)
41+
{
42+
$bindings = [];
43+
$destinationType = 'queue';
44+
$topic = 'async.#';
45+
$destination = 'async.operations.all';
46+
$bindingId = $destinationType . '--' . $destination . '--' . $topic;
47+
$bindings[$bindingId] = [
48+
'id' => $bindingId,
49+
'topic' => $topic,
50+
'destinationType' => $destinationType,
51+
'destination' => $destination,
52+
'disabled' => false,
53+
'arguments' => [],
54+
];
55+
56+
$name = 'magento';
57+
$connection = $this->getConnection();
58+
$result[$name . '--' . $connection] = [
59+
'name' => $name,
60+
'type' => 'topic',
61+
'connection' => $connection,
62+
'durable' => true,
63+
'autoDelete' => false,
64+
'arguments' => [],
65+
'internal' => false,
66+
'bindings' => $bindings,
67+
];
68+
69+
return $result;
70+
}
71+
72+
/**
73+
* Get connection
74+
*
75+
* @return string
76+
*/
77+
private function getConnection()
78+
{
79+
$connection = $this->defaultValueProvider->getConnection();
80+
// if db connection, return amqp instead.
81+
return $connection === 'db' ? WebApiAsyncConfig::DEFAULT_CONSUMER_CONNECTION : $connection;
82+
}
83+
}

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,7 @@
16821682
<type name="Magento\Framework\MessageQueue\Consumer\Config\CompositeReader">
16831683
<arguments>
16841684
<argument name="readers" xsi:type="array">
1685+
<item name="asyncServiceReader" xsi:type="object" sortOrder="0">Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader\Consumer</item>
16851686
<item name="xmlReader" xsi:type="object" sortOrder="10">Magento\Framework\MessageQueue\Consumer\Config\Xml\Reader</item>
16861687
<item name="envReader" xsi:type="object" sortOrder="20">Magento\Framework\MessageQueue\Consumer\Config\Env\Reader</item>
16871688
</argument>
@@ -1727,6 +1728,7 @@
17271728
<type name="Magento\Framework\MessageQueue\Topology\Config\CompositeReader">
17281729
<arguments>
17291730
<argument name="readers" xsi:type="array">
1731+
<item name="asyncServiceReader" xsi:type="object" sortOrder="0">Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader\Topology</item>
17301732
<item name="remoteServiceReader" xsi:type="object" sortOrder="10">Magento\Framework\MessageQueue\Topology\Config\RemoteService\Reader</item>
17311733
<item name="xmlReader" xsi:type="object" sortOrder="20">Magento\Framework\MessageQueue\Topology\Config\Xml\Reader</item>
17321734
</argument>

dev/tests/integration/etc/post-install-setup-command-config.php.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ return [
1616
'--remote-storage-region' => 'us-east-1'
1717
*/
1818
]
19+
],
20+
[
21+
'command' => 'setup:upgrade',
22+
'config' => []
1923
]
2024
];

0 commit comments

Comments
 (0)