/** * @param string $name * @throws OperationException * @return array */ protected function readQueueAttributes($name) { try { // grab url before in order to read attributes $queueUrl = $this->client->getQueueUrl(['QueueName' => $name]); $attributes = $this->client->getQueueAttributes(['QueueUrl' => $queueUrl->get('QueueUrl'), 'AttributeNames' => ['All']]); return $attributes->get('Attributes'); } catch (\Exception $e) { throw new OperationException(sprintf('Cannot read attributes for queue "%s":%s', $name, $e->getMessage()), $e->getCode(), $e); } }
/** * AwsSqsQueueAdapter constructor. * * @param string $queueName The name of the SQS queue * @param SqsClient $sqsClient An SQS client * @param array $config Array of config values */ public function __construct($queueName, SqsClient $sqsClient, $config = array()) { $this->queueName = $queueName; $this->sqsClient = $sqsClient; $this->sqsUrl = $this->sqsClient->getQueueUrl(array('QueueName' => $this->queueName))->get('QueueUrl'); $this->config = $config; }
/** * Constructor * * @param SqsClient $sqsClient * @param SqsQueueOptions $options * @param string $name * @param JobPluginManager $jobPluginManager */ public function __construct(SqsClient $sqsClient, SqsQueueOptions $options, $name, JobPluginManager $jobPluginManager) { $this->sqsClient = $sqsClient; $this->queueOptions = $options; parent::__construct($name, $jobPluginManager); // If an URL has explicitly been given in the options, let's use it, otherwise we dynamically fetch it if (!$this->queueOptions->getQueueUrl()) { $queue = $this->sqsClient->getQueueUrl(array('QueueName' => $name)); $this->queueOptions->setQueueUrl($queue['QueueUrl']); } }
/** * @param string $queueId * @return string */ protected function getQueueUrl($queueId) { if (empty($this->queueUrl)) { if (empty($queueId)) { $queueId = $this->getQueueId(); } $response = $this->queueClient->getQueueUrl(["QueueName" => $queueId]); $this->queueUrl = $response->get("QueueUrl"); } return $this->queueUrl; }
/** * Constructs the wrapper using the name of the queue and the aws credentials * * @param $name * @param $aws_credentials */ public function __construct($name, $aws_credentials) { try { // Setup the connection to the queue $this->name = $name; $this->aws_credentials = $aws_credentials; $this->sqs_client = new SqsClient($this->aws_credentials); // Get the queue URL $this->url = $this->sqs_client->getQueueUrl(array('QueueName' => $this->name))->get('QueueUrl'); } catch (Exception $e) { echo 'Error getting the queue url ' . $e->getMessage(); } }
/** * Executes the current command * * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $queueName = $input->getOption('queue'); try { $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $queueName])['QueueUrl']; } catch (SqsException $exception) { $output->writeln(sprintf('<error>Impossible to retrieve URL for queue "%s". Reason: %s</error>', $queueName, $exception->getMessage())); return; } $uri = rtrim($input->getOption('server'), '/') . '/' . ltrim($input->getOption('path'), '/'); while (true) { $messages = $this->sqsClient->receiveMessage(['QueueUrl' => $queueUrl, 'AttributeNames' => ['All'], 'MaxNumberOfMessages' => 1, 'WaitTimeSeconds' => 20]); if (!$messages->hasKey('Messages')) { continue; } $this->processMessage($messages['Messages'][0], $uri, $queueName, $queueUrl, $output); } }
public function getQueueUrl() { if (!$this->url) { $result = $this->client->getQueueUrl(["QueueName" => $this->name]); if ($result['QueueUrl']) { $this->url = $result['QueueUrl']; } else { throw new \RuntimeException("Cannot find queue url for queue named {$this->name}"); } } return $this->url; }
/** * Return the Queue Url * * This method relies on in-memory cache and the Cache provider * to reduce the need to needlessly call the create method on an existing * Queue. * * @return boolean */ public function queueExists() { if (isset($this->queueUrl)) { return true; } $key = $this->getNameWithPrefix() . '_url'; if ($this->cache->contains($key)) { $this->queueUrl = $this->cache->fetch($key); return true; } $result = $this->sqs->getQueueUrl(['QueueName' => $this->getNameWithPrefix()]); if ($this->queueUrl = $result->get('QueueUrl')) { return true; } return false; }
/** * @inheritdoc * * @throws SqsException */ public function purgeQueue($queueName, $priority = null) { if (null === $priority) { $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { $this->purgeQueue($queueName, $priority); } return $this; } if (empty($queueName)) { throw new InvalidArgumentException('Parameter queueName empty or not defined.'); } $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); $this->sqsClient->purgeQueue(['QueueUrl' => $queueUrl]); return $this; }
/** * @inheritdoc * * @throws \InvalidArgumentException * @throws QueueAccessException */ public function purgeQueue($queueName, Priority $priority = null) { if (null === $priority) { $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { $this->purgeQueue($queueName, $priority); } return $this; } if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); } try { $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); $this->sqsClient->purgeQueue(['QueueUrl' => $queueUrl]); } catch (SqsException $e) { throw new QueueAccessException('Cannot purge queue', 0, $e); } return $this; }
/** * @expectedException \Aws\Sqs\Exception\SqsException */ public function testErrorParsing() { $this->sqs->getQueueUrl(array('QueueName' => 'php-fake-queue')); }
/** * Returns queue url * @param string $queueName The name of the queue * @return string The queue url */ public function getQueueUrl($queueName) { if (array_key_exists($queueName, $this->queueUrls)) { return $this->queueUrls[$queueName]; } $result = $this->client->getQueueUrl(array('QueueName' => $queueName)); if ($result && ($queueUrl = $result['QueueUrl'])) { return $this->queueUrls[$queueName] = $queueUrl; } throw new \InvalidArgumentException("Queue url for queue {$queueName} not found"); }