当前位置: 首页>>代码示例>>PHP>>正文


PHP Sqs\SqsClient类代码示例

本文整理汇总了PHP中Aws\Sqs\SqsClient的典型用法代码示例。如果您正苦于以下问题:PHP SqsClient类的具体用法?PHP SqsClient怎么用?PHP SqsClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SqsClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCreateQueue

 public function testCreateQueue()
 {
     $queueName = 'test_queue';
     $db = DriverManager::getConnection(['driver' => 'pdo_mysql', 'host' => SYRUP_DATABASE_HOST, 'dbname' => SYRUP_DATABASE_NAME, 'user' => SYRUP_DATABASE_USER, 'password' => SYRUP_DATABASE_PASSWORD, 'port' => SYRUP_DATABASE_PORT]);
     $db->query("DELETE FROM queues WHERE id='{$queueName}'")->execute();
     $command = $this->application->find('syrup:queue:create');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['name' => $queueName, '--register' => null, '--no-watch' => null]);
     $this->assertEquals(0, $commandTester->getStatusCode());
     $factory = new QueueFactory($db, ['db_table' => 'queues'], SYRUP_APP_NAME);
     $dbQueue = $factory->get($queueName);
     $queueUrlArr = explode('/', $dbQueue->getUrl());
     $this->assertEquals($queueName, array_pop($queueUrlArr));
     $sqsClient = new SqsClient(['version' => '2012-11-05', 'region' => 'us-east-1']);
     $sqsClient->deleteQueue(['QueueUrl' => $dbQueue->getUrl()]);
 }
开发者ID:ErikZigo,项目名称:syrup,代码行数:16,代码来源:QueueCreateCommandTest.php

示例2: testValidatesSuccessfulMd5OfBody

 /**
  * @expectedException \Aws\Sqs\Exception\SqsException
  * @expectedExceptionMessage Body MD5 mismatch for
  */
 public function testValidatesSuccessfulMd5OfBody()
 {
     $mock = new MockPlugin(array(Response::fromMessage("HTTP/1.1 200 OK\r\nContent-Type: application/xml\r\n\r\n" . "<ReceiveMessageResponse>\n                  <ReceiveMessageResult>\n                    <Message>\n                      <MD5OfBody>fooo</MD5OfBody>\n                      <Body>This is a test message</Body>\n                    </Message>\n                  </ReceiveMessageResult>\n                </ReceiveMessageResponse>")));
     $sqs = SqsClient::factory(array('key' => 'abc', 'secret' => '123', 'region' => 'us-east-1'));
     $sqs->addSubscriber($mock);
     $sqs->receiveMessage(array('QueueUrl' => 'http://foo.com'));
 }
开发者ID:njbhatt18,项目名称:Amazon_API,代码行数:11,代码来源:SqsClientTest.php

示例3: openConnection

 /**
  * Connect to the queueing server. (AWS, Iron.io and Beanstalkd)
  * @param array $config
  * @return
  */
 public function openConnection($config)
 {
     $this->queue = \Aws\Sqs\SqsClient::factory(['credentials' => new \Aws\Common\Credentials\Credentials($config['key'], $config['secret']), 'region' => $config['region']]);
     if (!$this->queue) {
         throw new TestRuntime('connection failed or timed-out.');
     }
 }
开发者ID:namnv609,项目名称:Codeception,代码行数:12,代码来源:AmazonSQS.php

示例4: publish

 /**
  * Send message to sqs and trigger lambda
  *
  * @param string $message to be send via sqs
  *
  */
 public function publish($message)
 {
     // http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Sqs.SqsClient.html#_sendMessage
     $this->sqs->sendMessage(['QueueUrl' => $this->sqsQueueUrl, 'MessageBody' => $message]);
     // http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Sns.SnsClient.html#_publish
     $this->sns->publish(['TopicArn' => $this->snsTopicArn, 'Message' => 'SQS Message send', 'Subject' => 'SQS Message send']);
 }
开发者ID:mikolajprzybysz,项目名称:php-lambda-flow,代码行数:13,代码来源:Publisher.php

示例5: create

 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;
 }
开发者ID:ErikZigo,项目名称:syrup,代码行数:10,代码来源:QueueFactory.php

示例6: testCreate

 public function testCreate()
 {
     $db = DriverManager::getConnection(['driver' => 'pdo_mysql', 'host' => SYRUP_DATABASE_HOST, 'dbname' => SYRUP_DATABASE_NAME, 'user' => SYRUP_DATABASE_USER, 'password' => SYRUP_DATABASE_PASSWORD, 'port' => SYRUP_DATABASE_PORT]);
     $factory = new QueueFactory($db, ['db_table' => 'queues'], SYRUP_APP_NAME);
     $sqsQueue = $factory->create('test');
     $queueUrlArr = explode('/', $sqsQueue->get('QueueUrl'));
     $this->assertEquals('test', array_pop($queueUrlArr));
     // delete the queue from AWS
     $sqsClient = new SqsClient(['version' => '2012-11-05', 'region' => 'us-east-1']);
     $sqsClient->deleteQueue(['QueueUrl' => $sqsQueue->get('QueueUrl')]);
 }
开发者ID:ErikZigo,项目名称:syrup,代码行数:11,代码来源:QueueFactoryTest.php

示例7: 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");
     }
 }
开发者ID:keboola,项目名称:syrup-queue,代码行数:51,代码来源:InitKillQueueCommand.php

示例8: testGetQueueArn

 public function testGetQueueArn()
 {
     $url = 'https://sqs.us-east-1.amazonaws.com/057737625318/php-integ-sqs-queue-1359765974';
     $arn = 'arn:aws:sqs:us-east-1:057737625318:php-integ-sqs-queue-1359765974';
     $sqs = SqsClient::factory(array('region' => 'us-east-1'));
     $this->assertEquals($arn, $sqs->getQueueArn($url));
 }
开发者ID:cstuder,项目名称:nagios-plugins,代码行数:7,代码来源:SqsClientTest.php

示例9:

 function __construct()
 {
     $this->CI =& get_instance();
     $this->client = SqsClient::factory(array('key' => $this->CI->config->item('sqs_access_key_id'), 'secret' => $this->CI->config->item('sqs_secret_key'), 'region' => $this->CI->config->item('aws_region')));
     $this->uuid = $this->CI->config->item('uuid');
     $this->queue = $this->CI->config->item('sqs_queue');
 }
开发者ID:janladaking,项目名称:CodeIgniter,代码行数:7,代码来源:awssqslib.php

示例10: getConnection

 /**
  * Get the Aws Client instance
  * 
  * @return Aws\Sqs\SqsClient
  */
 public function getConnection()
 {
     //we have a stored connection
     if (!$this->_sqsClient) {
         $_config = $this->_getConfiguration();
         $this->_sqsClient = SqsClient::factory(array('key' => $_config['key'], 'secret' => $_config['secret'], 'region' => $_config['region']));
     }
     return $this->_sqsClient;
 }
开发者ID:svenvarkel,项目名称:magento-lilmuckers_queue,代码行数:14,代码来源:Amazon.php

示例11: readQueueAttributes

 /**
  * @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);
     }
 }
开发者ID:ronan-gloo,项目名称:qu,代码行数:16,代码来源:SqsQueueManager.php

示例12: testReturnMessage

 public function testReturnMessage()
 {
     $expectedArg = ["QueueUrl" => $this->queueUrl, "ReceiptHandle" => $this->receiptId, "VisibilityTimeout" => 0];
     $this->sqsClient->shouldReceive("changeMessageVisibility")->with($expectedArg)->once();
     $queue = new Queue($this->sqsClient, $this->messageFactory);
     $queue->returnMessage($this->queueMessage);
 }
开发者ID:silktide,项目名称:queueball-sqs,代码行数:7,代码来源:QueueTest.php

示例13: is_message

 /**
  *
  * @return number
  */
 public function is_message($queue = '')
 {
     $result = $this->sqs->getQueueAttributes(['QueueUrl' => $queue, 'AttributeNames' => ['ApproximateNumberOfMessages', 'ApproximateNumberOfMessagesNotVisible', 'ApproximateNumberOfMessagesDelayed']]);
     $queuecount = 0;
     foreach ($result->get("Attributes") as $key => $val) {
         $queuecount += $val;
     }
     return $queuecount;
 }
开发者ID:mithun12000,项目名称:yii2-queue,代码行数:13,代码来源:SqsQueue.php

示例14: processMessage

 /**
  * Process a single message and push it to the server URL
  *
  * @link   http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features-managing-env-tiers.html
  * @param  array           $message
  * @param  string          $uri
  * @param  string          $queueName
  * @param  string          $queueUrl
  * @param  OutputInterface $output
  * @return void
  */
 private function processMessage(array $message, string $uri, string $queueName, string $queueUrl, OutputInterface $output)
 {
     $response = $this->httpClient->post($uri, ['headers' => ['User-Agent' => 'aws-sqsd/2.0', 'Content-Type' => 'application/json', 'X-Aws-Sqsd-Msgid' => $message['MessageId'], 'X-Aws-Sqsd-Queue' => $queueName, 'X-Aws-Sqsd-First-Received-At' => $message['Attributes']['ApproximateFirstReceiveTimestamp'], 'X-Aws-Sqsd-Receive-Count' => $message['Attributes']['ApproximateReceiveCount'], 'X-Aws-Sqsd-Sender-Id' => $message['Attributes']['SenderId']], 'json' => json_decode($message['Body'], true)]);
     if ($response->getStatusCode() === 200) {
         $this->sqsClient->deleteMessage(['QueueUrl' => $queueUrl, 'ReceiptHandle' => $message['ReceiptHandle']]);
         $output->writeln(sprintf('<info>Message "%s" has been processed and deleted from the queue "%s".</info>', $message['MessageId'], $queueName));
     } else {
         $output->writeln(sprintf('<error>Message "%s" could not be processed and back-end returned error %s. Reason: %s</error>', $message['MessageId'], $response->getStatusCode(), $response->getBody()));
     }
 }
开发者ID:zf-fr,项目名称:zfr-eb-worker,代码行数:21,代码来源:WorkerCommand.php

示例15: delete

 /**
  * {@inheritDoc}
  */
 public function delete(MessageInterface $message)
 {
     if (null === $message->getAttribute('ReceiptHandle')) {
         throw new QueueException('Message does not contain ReceiptHandle');
     }
     $result = $this->client->deleteMessage(array('ReceiptHandle' => $message->getAttribute('ReceiptHandle'), 'QueueUrl' => $this->queueUrl));
 }
开发者ID:dspacelabs,项目名称:queue,代码行数:10,代码来源:SqsQueue.php


注:本文中的Aws\Sqs\SqsClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。