Skip to content

Commit 6fea198

Browse files
authored
Merge pull request #10 from se-sg/magento-2.3-compatibility
Make compatible with Magento 2.3
2 parents 7c06311 + 8883fa0 commit 6fea198

6 files changed

Lines changed: 129 additions & 29 deletions

File tree

Model/Config.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Config
3131
const ACCESS_KEY = 'access_key';
3232
const SECRET_KEY = 'secret_key';
3333
const PREFIX = 'prefix';
34+
const ENDPOINT = 'endpoint';
3435

3536
/**
3637
* Deployment configuration
@@ -69,6 +70,7 @@ class Config
6970
* 'access_key' => '123456',
7071
* 'secret_key' => '123456',
7172
* 'prefix' => 'magento',
73+
* 'endpoint' => 'http://localhost:4575'
7274
* ],
7375
* ],
7476
* </code>
@@ -91,7 +93,8 @@ public function getConnection()
9193
[
9294
'region' => $this->getValue(Config::REGION),
9395
'key' => $this->getValue(Config::ACCESS_KEY),
94-
'secret' => $this->getValue(Config::SECRET_KEY)
96+
'secret' => $this->getValue(Config::SECRET_KEY),
97+
'endpoint' => $this->getValue(Config::ENDPOINT)
9598
]
9699
))->createContext();
97100
}

Model/ConnectionTypeResolver.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* @package BelVG AWS Sqs.
4+
* @copyright 2018
5+
*
6+
*/
7+
namespace Belvg\Sqs\Model;
8+
9+
use Magento\Framework\MessageQueue\ConnectionTypeResolverInterface;
10+
use Magento\Framework\App\DeploymentConfig;
11+
12+
/**
13+
* AWS SQS connection type resolver.
14+
*
15+
* @api
16+
*/
17+
class ConnectionTypeResolver implements ConnectionTypeResolverInterface
18+
{
19+
/**
20+
* AWS SQS connection names.
21+
*
22+
* @var string[]
23+
*/
24+
private $sqsConnectionName = [];
25+
26+
/**
27+
* Initialize dependencies.
28+
*
29+
* @param DeploymentConfig $deploymentConfig
30+
* @since 100.0.0
31+
*/
32+
public function __construct(DeploymentConfig $deploymentConfig)
33+
{
34+
$queueConfig = $deploymentConfig->getConfigData(Config::QUEUE_CONFIG);
35+
if (isset($queueConfig['connections']) && is_array($queueConfig['connections'])) {
36+
$this->sqsConnectionName = array_keys($queueConfig['connections']);
37+
}
38+
if (isset($queueConfig[Config::SQS_CONFIG])) {
39+
$this->sqsConnectionName[] = Config::SQS_CONFIG;
40+
}
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
* @since 100.0.0
46+
*/
47+
public function getConnectionType($connectionName)
48+
{
49+
return in_array($connectionName, $this->sqsConnectionName) ? 'sqs' : null;
50+
}
51+
}

Model/ExchangeFactory.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* @package BelVG AWS Sqs.
4+
* @copyright 2018
5+
*
6+
*/
7+
8+
namespace Belvg\Sqs\Model;
9+
10+
/**
11+
* Factory class for @see \Belvg\Sqs\Model\Exchange
12+
*
13+
* @api
14+
*/
15+
class ExchangeFactory implements \Magento\Framework\MessageQueue\ExchangeFactoryInterface
16+
{
17+
/**
18+
* Object Manager instance
19+
*
20+
* @var \Magento\Framework\ObjectManagerInterface
21+
*/
22+
private $objectManager = null;
23+
24+
/**
25+
* Instance name to create
26+
*
27+
* @var string
28+
*/
29+
private $instanceName = null;
30+
31+
/**
32+
* Initialize dependencies.
33+
*
34+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
35+
* @param ConfigPool $configPool
36+
* @param string $instanceName
37+
* @since 100.0.0
38+
*/
39+
public function __construct(
40+
\Magento\Framework\ObjectManagerInterface $objectManager,
41+
$instanceName = \Belvg\Sqs\Model\Exchange::class
42+
) {
43+
$this->objectManager = $objectManager;
44+
$this->instanceName = $instanceName;
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
* @since 100.0.0
50+
*/
51+
public function create($connectionName, array $data = [])
52+
{
53+
return $this->objectManager->create($this->instanceName);
54+
}
55+
}

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"name": "belvg/module-sqs",
33
"description": "N/A",
44
"require": {
5-
"php": "7.0.2|7.0.4|~7.0.6",
6-
"magento/framework": "101.0.*",
7-
"magento/framework-message-queue": "100.2.*",
8-
"enqueue/sqs":"^0.4.9"
5+
"php": "~7.1.3||~7.2.0",
6+
"magento/framework": "^102.0.0",
7+
"magento/framework-message-queue": "^100.3.0",
8+
"enqueue/sqs":"@dev"
99
},
1010
"type": "magento2-module",
11-
"version": "0.5.0",
11+
"version": "0.6.0",
1212
"license": [
1313
"OSL-3.0",
1414
"AFL-3.0"
@@ -21,4 +21,4 @@
2121
"Belvg\\Sqs\\": ""
2222
}
2323
}
24-
}
24+
}

etc/di.xml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<type name="Magento\Framework\MessageQueue\QueueRepository">
55
<arguments>
6-
<argument name="queues" xsi:type="array">
6+
<argument name="queueFactories" xsi:type="array">
77
<item name="sqs" xsi:type="string">Belvg\Sqs\Model\Queue</item>
88
</argument>
99
</arguments>
1010
</type>
11-
<type name="Magento\Framework\MessageQueue\ExchangeRepository">
11+
<type name="Magento\Framework\MessageQueue\ExchangeFactory">
1212
<arguments>
13-
<argument name="exchanges" xsi:type="array">
14-
<item name="sqs" xsi:type="string">Belvg\Sqs\Model\Exchange</item>
13+
<argument name="exchangeFactories" xsi:type="array">
14+
<item name="sqs" xsi:type="object">Belvg\Sqs\Model\ExchangeFactory</item>
1515
</argument>
1616
</arguments>
1717
</type>
@@ -32,16 +32,10 @@
3232
<arguments>
3333
<argument name="publishers" xsi:type="array">
3434
<item name="async" xsi:type="array">
35-
<item name="sqs" xsi:type="array">
36-
<item name="type" xsi:type="object">Magento\Framework\MessageQueue\Publisher</item>
37-
<item name="connectionName" xsi:type="string">sqs</item>
38-
</item>
35+
<item name="sqs" xsi:type="object">Magento\Framework\MessageQueue\Publisher</item>
3936
</item>
4037
<item name="sync" xsi:type="array">
41-
<item name="sqs" xsi:type="array">
42-
<item name="type" xsi:type="object">Magento\Framework\MessageQueue\Rpc\Publisher</item>
43-
<item name="connectionName" xsi:type="string">sqs</item>
44-
</item>
38+
<item name="sqs" xsi:type="object">Magento\Framework\MessageQueue\Rpc\Publisher</item>
4539
</item>
4640
</argument>
4741
</arguments>
@@ -55,4 +49,11 @@
5549
</argument>
5650
</arguments>
5751
</type>
52+
<type name="Magento\Framework\MessageQueue\ConnectionTypeResolver">
53+
<arguments>
54+
<argument name="resolvers" xsi:type="array">
55+
<item name="sqs" xsi:type="object">Belvg\Sqs\Model\ConnectionTypeResolver</item>
56+
</argument>
57+
</arguments>
58+
</type>
5859
</config>

etc/queue.xml

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

0 commit comments

Comments
 (0)