Skip to content

Commit

Permalink
Add custom endpoints for using in local environment. Compatibly with …
Browse files Browse the repository at this point in the history
…magento 2.1.3 and php 7.0
  • Loading branch information
galillei committed Aug 15, 2019
1 parent cbaa0e7 commit e6ae39c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
7 changes: 5 additions & 2 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Config
const ACCESS_KEY = 'access_key';
const SECRET_KEY = 'secret_key';
const PREFIX = 'prefix';
const ENDPOINT = 'endpoint';

/**
* Deployment configuration
Expand Down Expand Up @@ -69,6 +70,7 @@ class Config
* 'access_key' => '123456',
* 'secret_key' => '123456',
* 'prefix' => 'magento',
* 'endpoint' => 'http://localhost:4575'
* ],
* ],
* </code>
Expand All @@ -91,7 +93,8 @@ public function getConnection()
[
'region' => $this->getValue(Config::REGION),
'key' => $this->getValue(Config::ACCESS_KEY),
'secret' => $this->getValue(Config::SECRET_KEY)
'secret' => $this->getValue(Config::SECRET_KEY),
'endpoint' => $this->getValue(Config::ENDPOINT)
]
))->createContext();
}
Expand Down Expand Up @@ -123,4 +126,4 @@ private function load()
$this->data = isset($queueConfig[self::SQS_CONFIG]) ? $queueConfig[self::SQS_CONFIG] : [];
}
}
}
}
11 changes: 6 additions & 5 deletions Model/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Belvg\Sqs\Helper\Data;
use Enqueue\Psr\PsrMessage;
use Enqueue\Sqs\SqsMessage;
use Magento\Framework\MessageQueue\EnvelopeFactory;
use Magento\Framework\MessageQueue\EnvelopeInterface;
use Magento\Framework\MessageQueue\QueueInterface;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function __construct(
public function dequeue()
{
/**
* @var \Enqueue\Sqs\SqsMessage $message
* @var SqsMessage $message
*/
$message = $this->createConsumer()->receive(self::TIMEOUT_PROCESS);
if (null !== $message) {
Expand Down Expand Up @@ -116,7 +117,7 @@ protected function getQueueName()
return $this->sqsConfig->getValue(Config::PREFIX) . '_' . Data::prepareQueueName($this->queueName);
}

protected function createEnvelop(PsrMessage $message)
protected function createEnvelop(SqsMessage $message)
{
return $this->envelopeFactory->create([
'body' => $message->getBody(),
Expand All @@ -141,7 +142,7 @@ public function acknowledge(EnvelopeInterface $envelope)

/**
* @param EnvelopeInterface $envelopereceiptHandle
* @return \Enqueue\Sqs\SqsMessage
* @return SqsMessage
*/
protected function createMessage(EnvelopeInterface $envelope)
{
Expand All @@ -164,7 +165,7 @@ public function subscribe($callback, int $qtyOfMessages = null)
$index = 0;
while (true) {
/**
* @var \Enqueue\Sqs\SqsMessage $message
* @var SqsMessage $message
*/
if ($message = $this->createConsumer()->receive(self::TIMEOUT_PROCESS)) {
$index++;
Expand All @@ -175,7 +176,7 @@ public function subscribe($callback, int $qtyOfMessages = null)
} else {
call_user_func($callback, $envelope);
}
//$this->createConsumer()->acknowledge($message);
// $this->createConsumer()->acknowledge($message);
if (null !== $qtyOfMessages && $index >= $qtyOfMessages) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Topology.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private function deleteQueue($queueName)
private function purgeQueue($queueName)
{
$sqsQueueName = $this->getConnection()->createQueue($this->getQueueName($queueName));
$this->getConnection()->purge($sqsQueueName);
$this->getConnection()->purgeQueue($sqsQueueName);
}


Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"php": "7.0.2|7.0.4|~7.0.6",
"magento/framework": "101.0.*",
"magento/framework-message-queue": "100.2.*",
"enqueue/sqs":"^0.4.9"
"enqueue/sqs":"0.8.20"
},
"type": "magento2-module",
"version": "0.5.0",
"version": "0.8.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Belvg_Sqs" setup_version="0.0.3"/>
<module name="Belvg_Sqs" setup_version="0.8.0"/>
</config>

0 comments on commit e6ae39c

Please sign in to comment.