本文整理汇总了PHP中Aws\Sqs\SqsClient::setQueueAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP SqsClient::setQueueAttributes方法的具体用法?PHP SqsClient::setQueueAttributes怎么用?PHP SqsClient::setQueueAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\Sqs\SqsClient
的用法示例。
在下文中一共展示了SqsClient::setQueueAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* {@inheritDoc}
*/
public function update(QueueAdapterInterface $queue)
{
if (!$queue instanceof SqsQueue) {
throw new InvalidArgumentException('expecting an instance of SqsQueue');
}
// Update queue attributes if required
$Attributes = $queue->getConfig()->toAttributes();
$QueueUrl = $queue->getUrl();
$this->client->setQueueAttributes(compact('QueueUrl', 'Attributes'));
}
示例2: createQueue
/**
* 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");
}
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$noWatch = $input->getOption('no-watch');
$queueId = $this->getQueueId();
$snsConfig = $this->getContainer()->getParameter('sns');
$region = isset($snsConfig['region']) ? $snsConfig['region'] : 'us-east-1';
/** @var QueueFactory $queueFactory */
$queueFactory = $this->getContainer()->get('syrup.queue_factory');
$sqs = $queueFactory->create($queueId, $region, $snsConfig['key'], $snsConfig['secret']);
/** @var Connection $conn */
$conn = $this->getContainer()->get('doctrine.dbal.syrup_connection');
$stmt = $conn->query("SELECT * FROM queues WHERE id='{$queueId}'");
$res = $stmt->fetchAll();
if (empty($res)) {
$conn->insert('queues', ['id' => $queueId, 'access_key' => $snsConfig['key'], 'secret_key' => $snsConfig['secret'], 'region' => $region, 'url' => $sqs->get('QueueUrl')]);
}
$sqsClient = new SqsClient(['region' => $region, 'version' => '2012-11-05', 'credentials' => ['key' => $snsConfig['key'], 'secret' => $snsConfig['secret']]]);
$sqsArn = $sqsClient->getQueueArn($sqs->get('QueueUrl'));
// subscribe SQS to SNS
$snsClient = new SnsClient(['region' => $region, 'version' => '2010-03-31', 'credentials' => ['key' => $snsConfig['key'], 'secret' => $snsConfig['secret']]]);
$snsClient->subscribe(['TopicArn' => $snsConfig['topic_arn'], 'Protocol' => 'sqs', 'Endpoint' => $sqsArn]);
// add policy to SQS to allow SNS sending messages to it
$sqsPolicy = '{
"Version": "2008-10-17",
"Id": "' . $sqsArn . '/SQSDefaultPolicy",
"Statement": [
{
"Sid": "sqs-sns",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "SQS:SendMessage",
"Resource": "' . $sqsArn . '",
"Condition": {
"ArnEquals": {
"aws:SourceArn": "' . $snsConfig['topic_arn'] . '"
}
}
}
]
}';
$sqsClient->setQueueAttributes(['QueueUrl' => $sqs->get('QueueUrl'), 'Attributes' => ['Policy' => $sqsPolicy]]);
$output->writeln("SQS created and registered to SNS");
// Add Cloudwatch alarm
if (!$noWatch) {
$cwClient = new CloudWatchClient(['region' => $region, 'version' => '2010-08-01', 'credentials' => ['key' => $snsConfig['key'], 'secret' => $snsConfig['secret']]]);
$cwClient->putMetricAlarm(['AlarmName' => sprintf('Syrup %s queue is full', $queueId), 'ActionsEnabled' => true, 'AlarmActions' => [$snsConfig['alarm_topic_arn']], 'MetricName' => 'ApproximateNumberOfMessagesVisible', 'Namespace' => 'AWS/SQS', 'Statistic' => 'Average', 'Dimensions' => [['Name' => 'QueueName', 'Value' => $queueId]], 'Period' => 300, 'EvaluationPeriods' => 1, 'Threshold' => 5, 'ComparisonOperator' => 'GreaterThanOrEqualToThreshold']);
$output->writeln("Cloudwatch alarm created");
}
}
示例4: setAttributes
public function setAttributes(array $attributes)
{
$args = ['QueueUrl' => $this->getQueueUrl()];
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;
} else {
throw new \InvalidArgumentException("You must specify some attributes");
}
$this->client->setQueueAttributes($args);
}
示例5: createQueue
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)));
}