81 lines
1.8 KiB
PHP
Executable File
81 lines
1.8 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Copyright 2023 JR or its affiliates. All Rights Reserved.
|
|
*
|
|
*/
|
|
|
|
namespace JR\Customer\Model;
|
|
|
|
use Aws\Exception\AwsException;
|
|
use Aws\Sqs\SqsClient;
|
|
|
|
class SqsAdapter
|
|
{
|
|
/**
|
|
* @var SqsClient
|
|
*/
|
|
protected $client;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
|
|
// $this->client = new SqsClient([
|
|
// 'version' => 'latest',
|
|
// 'region' => $config->getDefaultRegion(),
|
|
// 'credentials' => [
|
|
// 'key' => $config->getAccessKey(),
|
|
// 'secret' => $config->getSecret()
|
|
// ],
|
|
// ]);
|
|
|
|
$this->client = new SqsClient([
|
|
'version' => 'latest',
|
|
'region' => 'us-west-1',
|
|
'credentials' => [
|
|
'key' => 'AKIAI255FGJWZPKYHE2Q',
|
|
'secret' => 'BqWVBucfi6omK4ejpoVJSk2NmN6xch+bO8hwliYa'
|
|
],
|
|
]);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @return \Aws\Result
|
|
* @throws AwsException
|
|
*/
|
|
public function getQueues()
|
|
{
|
|
return $this->client->listQueues();
|
|
}
|
|
|
|
/**
|
|
* @param array $args
|
|
* @return string
|
|
*/
|
|
public function getQueueUrl($args)
|
|
{
|
|
$result = $this->client->getQueueUrl($args);
|
|
return $result->get('QueueUrl');
|
|
}
|
|
|
|
/**
|
|
* @param string $queueUrl
|
|
* @param string $body
|
|
* @param array $attributes
|
|
* @param int $delay
|
|
* @return \Aws\Result
|
|
* @throws AwsException
|
|
*/
|
|
public function sendMessage($queueUrl, $body, $attributes = [], $delay = 0)
|
|
{
|
|
$params = [
|
|
'DelaySeconds' => $delay,
|
|
'MessageAttributes' => $attributes,
|
|
'MessageBody' => $body,
|
|
'QueueUrl' => $queueUrl
|
|
];
|
|
return $this->client->sendMessage($params);
|
|
}
|
|
} |