|
23 | 23 | namespace Uecode\Bundle\QPushBundle\Provider; |
24 | 24 |
|
25 | 25 | use Aws\Sns\SnsClient; |
| 26 | +use Aws\Sns\Exception\NotFoundException; |
26 | 27 | use Aws\Sqs\SqsClient; |
27 | 28 | use Aws\Sqs\Exception\SqsException; |
28 | 29 |
|
@@ -73,10 +74,11 @@ public function __construct($name, array $options, $client, Cache $cache, Logger |
73 | 74 | $this->options = $options; |
74 | 75 | $this->cache = $cache; |
75 | 76 | $this->logger = $logger; |
| 77 | + |
76 | 78 | // get() method used for sdk v2, create methods for v3 |
77 | 79 | $useGet = method_exists($client, 'get'); |
78 | | - $this->sqs = $useGet ? $client->get('Sqs') : $client->createSqs(); |
79 | | - $this->sns = $useGet ? $client->get('Sns') : $client->createSns(); |
| 80 | + $this->sqs = $useGet ? $client->get('Sqs') : $client->createSqs(); |
| 81 | + $this->sns = $useGet ? $client->get('Sns') : $client->createSns(); |
80 | 82 | } |
81 | 83 |
|
82 | 84 | public function getProvider() |
@@ -315,13 +317,17 @@ public function queueExists() |
315 | 317 | return true; |
316 | 318 | } |
317 | 319 |
|
318 | | - $result = $this->sqs->getQueueUrl([ |
319 | | - 'QueueName' => $this->getNameWithPrefix() |
320 | | - ]); |
| 320 | + try { |
| 321 | + $result = $this->sqs->getQueueUrl([ |
| 322 | + 'QueueName' => $this->getNameWithPrefix() |
| 323 | + ]); |
321 | 324 |
|
322 | | - if($this->queueUrl = $result->get('QueueUrl')) { |
323 | | - return true; |
324 | | - } |
| 325 | + if ($this->queueUrl = $result->get('QueueUrl')) { |
| 326 | + $this->cache->save($key, $this->queueUrl); |
| 327 | + |
| 328 | + return true; |
| 329 | + } |
| 330 | + } catch (SqsException $e) {} |
325 | 331 |
|
326 | 332 | return false; |
327 | 333 | } |
@@ -413,6 +419,24 @@ public function topicExists() |
413 | 419 | return true; |
414 | 420 | } |
415 | 421 |
|
| 422 | + if (!empty($this->queueUrl)) { |
| 423 | + $queueArn = $this->sqs->getQueueArn($this->queueUrl); |
| 424 | + $topicArn = str_replace('sqs', 'sns', $queueArn); |
| 425 | + |
| 426 | + try { |
| 427 | + $this->sns->getTopicAttributes([ |
| 428 | + 'TopicArn' => $topicArn |
| 429 | + ]); |
| 430 | + } catch (NotFoundException $e) { |
| 431 | + return false; |
| 432 | + } |
| 433 | + |
| 434 | + $this->topicArn = $topicArn; |
| 435 | + $this->cache->save($key, $this->topicArn); |
| 436 | + |
| 437 | + return true; |
| 438 | + } |
| 439 | + |
416 | 440 | return false; |
417 | 441 | } |
418 | 442 |
|
|
0 commit comments