Skip to content

Commit 6e52223

Browse files
committed
B2B-2171: Enable WebapiAsync work with redis connection
1 parent 5c30493 commit 6e52223

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,27 @@
99
namespace Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader;
1010

1111
use Magento\AsynchronousOperations\Model\ConfigInterface as WebApiAsyncConfig;
12+
use Magento\Framework\MessageQueue\DefaultValueProvider;
1213

1314
/**
1415
* Remote service reader with auto generated configuration for queue_consumer.xml
1516
*/
1617
class Consumer implements \Magento\Framework\Config\ReaderInterface
1718
{
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+
1833
/**
1934
* Generate consumer configuration based on remote services declarations
2035
*
@@ -31,7 +46,7 @@ public function read($scope = null)
3146
'name' => $topicName,
3247
'queue' => $topicName,
3348
'consumerInstance' => WebApiAsyncConfig::DEFAULT_CONSUMER_INSTANCE,
34-
'connection' => WebApiAsyncConfig::DEFAULT_CONSUMER_CONNECTION,
49+
'connection' => $this->getConnection(),
3550
'maxMessages' => WebApiAsyncConfig::DEFAULT_CONSUMER_MAX_MESSAGE,
3651
'handlers' => [],
3752
'maxIdleTime' => null,
@@ -41,4 +56,16 @@ public function read($scope = null)
4156

4257
return $result;
4358
}
59+
60+
/**
61+
* Get connection
62+
*
63+
* @return string
64+
*/
65+
private function getConnection()
66+
{
67+
$connection = $this->defaultValueProvider->getConnection();
68+
// if db connection, return amqp instead.
69+
return $connection === 'db' ? WebApiAsyncConfig::DEFAULT_CONSUMER_CONNECTION : $connection;
70+
}
4471
}

dev/tests/integration/framework/Magento/TestFramework/MessageQueue/PublisherConsumerController.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\Framework\MessageQueue\PublisherInterface;
1212
use Magento\Framework\OsInfo;
13+
use Magento\TestFramework\Helper\Bootstrap;
1314
use Magento\TestFramework\Helper\Amqp;
1415

1516
/**
@@ -52,6 +53,11 @@ class PublisherConsumerController
5253
*/
5354
private $amqpHelper;
5455

56+
/**
57+
* @var ClearQueueProcessor
58+
*/
59+
private $clearQueueProcessor;
60+
5561
/**
5662
* PublisherConsumerController constructor.
5763
* @param PublisherInterface $publisher
@@ -61,6 +67,7 @@ class PublisherConsumerController
6167
* @param array $consumers
6268
* @param array $appInitParams
6369
* @param null|int $maxMessages
70+
* @param ClearQueueProcessor $clearQueueProcessor
6471
*/
6572
public function __construct(
6673
PublisherInterface $publisher,
@@ -69,7 +76,8 @@ public function __construct(
6976
$logFilePath,
7077
$consumers,
7178
$appInitParams,
72-
$maxMessages = null
79+
$maxMessages = null,
80+
ClearQueueProcessor $clearQueueProcessor = null
7381
) {
7482
$this->consumers = $consumers;
7583
$this->publisher = $publisher;
@@ -78,6 +86,9 @@ public function __construct(
7886
$this->osInfo = $osInfo;
7987
$this->appInitParams = $appInitParams;
8088
$this->amqpHelper = $amqpHelper;
89+
$this->clearQueueProcessor = $clearQueueProcessor
90+
?: Bootstrap::getObjectManager()->get(ClearQueueProcessor::class);
91+
8192
}
8293

8394
/**
@@ -90,12 +101,7 @@ public function initialize()
90101
{
91102
$this->validateEnvironmentPreconditions();
92103

93-
$connections = $this->amqpHelper->getConnections();
94-
foreach (array_keys($connections) as $connectionName) {
95-
$this->amqpHelper->deleteConnection($connectionName);
96-
}
97-
$this->amqpHelper->clearQueue("async.operations.all");
98-
104+
$this->clearQueueProcessor->execute("async.operations.all");
99105
$this->stopConsumers();
100106
$this->startConsumers();
101107

@@ -123,12 +129,6 @@ private function validateEnvironmentPreconditions()
123129
"This test relies on *nix shell and should be skipped in Windows environment."
124130
);
125131
}
126-
127-
if (!$this->amqpHelper->isAvailable()) {
128-
throw new PreconditionFailedException(
129-
'This test relies on RabbitMQ Management Plugin.'
130-
);
131-
}
132132
}
133133

134134
/**

0 commit comments

Comments
 (0)