Skip to content

Commit d3b1e1d

Browse files
committed
MCP-826: Use RabbitMQ for all consumers if AMQP is set in deployment config
- Make db as a default connection for integration and web api tests;
1 parent 4f2848b commit d3b1e1d

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

app/code/Magento/MessageQueue/Setup/ConfigOptionsList.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\DeploymentConfig;
1313
use Magento\Framework\Config\Data\ConfigData;
1414
use Magento\Framework\Config\File\ConfigFilePool;
15+
use Magento\Framework\Setup\Option\TextConfigOption;
1516

1617
/**
1718
* Deployment configuration consumers options needed for Setup application
@@ -22,16 +23,19 @@ class ConfigOptionsList implements ConfigOptionsListInterface
2223
* Input key for the option
2324
*/
2425
const INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES ='consumers-wait-for-messages';
26+
const INPUT_KEY_QUEUE_DEFAULT_CONNECTION ='default-connection';
2527

2628
/**
27-
* Path to the value in the deployment config
29+
* Path to the values in the deployment config
2830
*/
2931
const CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES = 'queue/consumers_wait_for_messages';
32+
const CONFIG_PATH_QUEUE_DEFAULT_CONNECTION = 'queue/default_connection';
3033

3134
/**
3235
* Default value
3336
*/
3437
const DEFAULT_CONSUMERS_WAIT_FOR_MESSAGES = 1;
38+
const DEFAULT_CONNECTION = 'db';
3539

3640
/**
3741
* The available configuration values
@@ -54,6 +58,13 @@ public function getOptions()
5458
'Should consumers wait for a message from the queue? 1 - Yes, 0 - No',
5559
self::DEFAULT_CONSUMERS_WAIT_FOR_MESSAGES
5660
),
61+
new TextConfigOption(
62+
self::INPUT_KEY_QUEUE_DEFAULT_CONNECTION,
63+
TextConfigOption::FRONTEND_WIZARD_TEXT,
64+
self::CONFIG_PATH_QUEUE_DEFAULT_CONNECTION,
65+
'Default queue connection. Can be db, amqp or a custom one.',
66+
self::DEFAULT_CONNECTION
67+
),
5768
];
5869
}
5970

@@ -72,6 +83,13 @@ public function createConfig(array $data, DeploymentConfig $deploymentConfig)
7283
);
7384
}
7485

86+
if (!$this->isDataEmpty($data, self::INPUT_KEY_QUEUE_DEFAULT_CONNECTION)) {
87+
$configData->set(
88+
self::CONFIG_PATH_QUEUE_DEFAULT_CONNECTION,
89+
$data[self::INPUT_KEY_QUEUE_DEFAULT_CONNECTION]
90+
);
91+
}
92+
7593
return [$configData];
7694
}
7795

@@ -87,6 +105,16 @@ public function validate(array $options, DeploymentConfig $deploymentConfig)
87105
$errors[] = 'You can use only 1 or 0 for ' . self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES . ' option';
88106
}
89107

108+
if ($this->isDataEmpty($options, self::INPUT_KEY_QUEUE_DEFAULT_CONNECTION)) {
109+
$errors[] = self::INPUT_KEY_QUEUE_DEFAULT_CONNECTION . ' option cannot be empty';
110+
}
111+
112+
if (!$this->isDataEmpty($options, self::INPUT_KEY_QUEUE_DEFAULT_CONNECTION)
113+
&& !is_string($options[self::INPUT_KEY_QUEUE_DEFAULT_CONNECTION])) {
114+
$errors[] = 'You can use only string type variable for '
115+
. self::INPUT_KEY_QUEUE_DEFAULT_CONNECTION . ' option';
116+
}
117+
90118
return $errors;
91119
}
92120

dev/tests/api-functional/config/post-install-setup-command-config.php.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ return [
1313
'--remote-storage-driver' => 'aws-s3',
1414
'--remote-storage-bucket' => 'myBucket',
1515
'--remote-storage-region' => 'us-east-1',
16+
'--default-connection' => 'db'
1617
]
1718
]
1819
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ return [
1313
'--remote-storage-driver' => 'aws-s3',
1414
'--remote-storage-bucket' => 'myBucket',
1515
'--remote-storage-region' => 'us-east-1',
16+
'--default-connection' => 'db'
1617
]
1718
]
1819
*/

dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/ConsumerTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Magento\ImportExport\Model\Export;
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
11-
use Magento\Framework\App\DeploymentConfig;
1211
use Magento\Framework\App\Filesystem\DirectoryList;
1312
use Magento\Framework\Filesystem;
1413
use Magento\Framework\Filesystem\Directory\WriteInterface;
@@ -46,11 +45,6 @@ class ConsumerTest extends TestCase
4645
/** @var string */
4746
private $filePath;
4847

49-
/**
50-
* @var DeploymentConfig|null
51-
*/
52-
private $deploymentConfig;
53-
5448
/**
5549
* @inheritdoc
5650
*/
@@ -64,7 +58,6 @@ protected function setUp(): void
6458
$this->consumer = $this->objectManager->get(Consumer::class);
6559
$filesystem = $this->objectManager->get(Filesystem::class);
6660
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
67-
$this->deploymentConfig = $this->objectManager->get(DeploymentConfig::class);
6861
}
6962

7063
/**
@@ -89,7 +82,6 @@ protected function tearDown(): void
8982
*/
9083
public function testProcess(): void
9184
{
92-
echo "Deployment config for queue is: " . json_encode($this->deploymentConfig->get('queue'));
9385
$envelope = $this->queue->dequeue();
9486
$decodedMessage = $this->messageEncoder->decode('import_export.export', $envelope->getBody());
9587
$this->consumer->process($decodedMessage);

lib/internal/Magento/Framework/MessageQueue/DefaultValueProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public function getConnection()
5959
// get amqp or default_connection if it is set in deployment configuration
6060
// otherwise use db as a default connection
6161
if (isset($this->config)) {
62-
if ($this->config->get('queue/amqp') && count($this->config->get('queue/amqp')) > 0) {
63-
$this->connection = 'amqp';
64-
} elseif ($this->config->get('queue/default_connection')) {
62+
if ($this->config->get('queue/default_connection')) {
6563
$this->connection = $this->config->get('queue/default_connection');
64+
} elseif ($this->config->get('queue/amqp') && count($this->config->get('queue/amqp')) > 0) {
65+
$this->connection = 'amqp';
6666
}
6767
}
6868
return $this->connection;

0 commit comments

Comments
 (0)