/** * {@inheritDoc} */ public function createQueue($queueId, $options = []) { $timeout = empty($options["messageLockTimeout"]) || !is_numeric($options["messageLockTimeout"]) ? self::DEFAULT_MESSAGE_LOCK_TIMEOUT : (int) $options["messageLockTimeout"]; $attributes = ["VisibilityTimeout" => $timeout]; $this->queueClient->createQueue(["QueueName" => $queueId, "Attributes" => $attributes]); $this->setQueueId($queueId); }
/** * {@inheritDoc} */ public function create($options) { if (!$options instanceof SqsQueueConfig) { throw new InvalidArgumentException('$options cannot be used to create a new queue'); } // SQS is resilient when creating a new queue, only if attributes are similar try { $this->client->createQueue(['QueueName' => $this->prepareQueueName($options->getName()), 'Attributes' => $options->toAttributes()]); } catch (\Exception $e) { throw new RuntimeException('Cannot create the queue with name ' . $options->getName(), $e->getCode(), $e); } $options->setAccountId($this->config->getAccountId()); return new SqsQueue($this->client, $options); }
public function createQueue(array $attributes = []) { $args = ['QueueName' => $this->name]; if ($attributes) { /** @noinspection PhpUnusedLocalVariableInspection */ foreach ($attributes as $k => &$v) { if (!in_array($k, self::MUTABLE_ATTRIBUTES)) { throw new \InvalidArgumentException("Unknown attribute {$k}"); } } $args['Attributes'] = $attributes; } $result = $this->client->createQueue($args); $this->url = $result['QueueUrl']; }
/** * Create new Amazon SQS driver. * * You have to create aws client instnace and provide it to this driver. * You can use service builder or factory method. * * <code> * use Aws\Sqs\SqsClient; * * $client = SqsClient::factory(array( * 'profile' => '<profile in your aws credentials file>', * 'region' => '<region name>' * )); * </code> * * or * * <code> * use Aws\Common\Aws; * * // Create a service builder using a configuration file * $aws = Aws::factory('/path/to/my_config.json'); * * // Get the client from the builder by namespace * $client = $aws->get('Sqs'); * </code> * * More examples see: https://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-sqs.html * * * @see examples/sqs folder * * @param SqsClient $client * @param string $queueName * @param array $queueAttributes */ public function __construct(SqsClient $client, $queueName, $queueAttributes = []) { $this->client = $client; $this->queueName = $queueName; $this->serializer = new MessageSerializer(); $result = $client->createQueue(['QueueName' => $queueName, 'Attributes' => $queueAttributes]); $this->queueUrl = $result->get('QueueUrl'); }
public function create($name, $region = 'us-east-1', $key = null, $secret = null) { $data = ['region' => $region, 'version' => '2012-11-05', 'retries' => 40]; if ($key != null && $secret != null) { $data['credentials'] = ['key' => $key, 'secret' => $secret]; } $sqsClient = new SqsClient($data); $sqsQueue = $sqsClient->createQueue(['QueueName' => $name]); return $sqsQueue; }
/** * @inheritdoc * * @throws SqsException */ public function createQueue($queueName) { if (empty($queueName)) { throw new InvalidArgumentException('Parameter queueName empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { $this->sqsClient->createQueue(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority), 'Attributes' => []]); } return $this; }
/** * Creates an SQS Queue and returns the Queue Url * * The create method for SQS Queues is idempotent - if the queue already * exists, this method will return the Queue Url of the existing Queue. * * @return string */ public function createQueue() { $result = $this->sqs->createQueue(['QueueName' => $this->getNameWithPrefix(), 'Attributes' => ['VisibilityTimeout' => $this->options['message_timeout'], 'MessageRetentionPeriod' => $this->options['message_expiration'], 'ReceiveMessageWaitTimeSeconds' => $this->options['receive_wait_time']]]); $this->queueUrl = $result->get('QueueUrl'); $key = $this->getNameWithPrefix() . '_url'; $this->cache->save($key, $this->queueUrl); $this->log(200, "Created SQS Queue", ['QueueUrl' => $this->queueUrl]); if ($this->options['push_notifications']) { $policy = $this->createSqsPolicy(); $this->sqs->setQueueAttributes(['QueueUrl' => $this->queueUrl, 'Attributes' => ['Policy' => $policy]]); $this->log(200, "Created Updated SQS Policy"); } }
/** * @inheritdoc * * @throws \InvalidArgumentException * @throws QueueAccessException */ public function createQueue($queueName) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { try { $this->sqsClient->createQueue(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority), 'Attributes' => []]); } catch (SqsException $e) { throw new QueueAccessException('Cannot create queue', 0, $e); } } return $this; }
/** * @depends testCreatesTopic */ public function testSubscribesToTopic($topicArn) { // Create an SQS queue for the test self::log('Creating a SQS queue'); $result = $this->sqs->createQueue(array('QueueName' => self::$queueName)); self::$queueUrl = $result['QueueUrl']; $queueArn = $this->sqs->getQueueArn(self::$queueUrl); // Subscribe to the SNS topic using an SQS queue self::log('Subscribing to the topic using the queue'); $result = $this->sns->subscribe(array('TopicArn' => self::$topicArn, 'Endpoint' => $queueArn, 'Protocol' => 'sqs')); // Ensure that the result has a SubscriptionArn self::log('Subscribe result: ' . var_export($result->toArray(), true)); $this->assertArrayHasKey('SubscriptionArn', $result->toArray()); self::$subscriptionArn = $result['SubscriptionArn']; return self::$subscriptionArn; }
private function createQueue() { $result = $this->client->createQueue(array('QueueName' => $this->queueName)); $this->queueUrl = $result->get('QueueUrl'); $this->client->setQueueAttributes(array('QueueUrl' => $this->queueUrl, 'Attributes' => array('VisibilityTimeout' => $this->visibilityTimeout))); }
public function addQueue($queueName) { $result = $this->service->createQueue(array('QueueName' => $queueName)); $queueUrl = $result->get('QueueUrl'); return $queueUrl; }