-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from abacaphiliac/extended-clients
add extended SQS and SNS clients
- Loading branch information
Showing
42 changed files
with
2,586 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
AWS_REGION="us-west-2" | ||
AWS_VERSION="latest" | ||
AWS_ACCOUNT="MyAwsAccount" | ||
AWS_KEY="foo" | ||
AWS_SECRET="bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
vendor | ||
.env | ||
behat.yml | ||
composer.lock | ||
coverage.clover | ||
phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
language: php | ||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- hhvm | ||
env: | ||
- COMPOSER_OPTS="" | ||
- COMPOSER_OPTS="--prefer-lowest" | ||
matrix: | ||
allow_failures: | ||
- php: hhvm | ||
fast_finish: true | ||
before_script: | ||
- composer self-update | ||
- composer install --no-interaction | ||
script: | ||
- vendor/bin/phing | ||
after_script: | ||
- wget https://scrutinizer-ci.com/ocular.phar | ||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,60 @@ | ||
# aws-php-claim-check-sdk | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/abacaphiliac/aws-sdk-php-claim-check/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/abacaphiliac/aws-sdk-php-claim-check/?branch=master) | ||
[![Code Coverage](https://scrutinizer-ci.com/g/abacaphiliac/aws-sdk-php-claim-check/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/abacaphiliac/aws-sdk-php-claim-check/?branch=master) | ||
[![Build Status](https://travis-ci.org/abacaphiliac/aws-sdk-php-claim-check.svg?branch=master)](https://travis-ci.org/abacaphiliac/aws-sdk-php-claim-check) | ||
|
||
# abacaphiliac/aws-php-claim-check-sdk | ||
|
||
An implementation of the | ||
[Claim Check](http://www.enterpriseintegrationpatterns.com/patterns/messaging/StoreInLibrary.html) | ||
Enterprise Integration Pattern, utilizing Amazon Web Services. AWS recommends usage of the Claim Check pattern on the | ||
[SQS Compliance FAQ](https://aws.amazon.com/sqs/faqs/#Compliance). | ||
|
||
![StoreInLibrary](http://www.enterpriseintegrationpatterns.com/img/StoreInLibrary.gif "StoreInLibrary") | ||
|
||
This library provides extended SNS and SQS clients to "Check Luggage", uses S3 as the "Data Store", | ||
and uses the extended SQS client as the "Data Enricher". | ||
|
||
This package aims to be a compatible port of | ||
Amazon's [Extended Client Library](https://github.com/awslabs/amazon-sqs-java-extended-client-lib). | ||
Messages stored via this PHP package should be able to be received by the Java package. | ||
|
||
# AWS [Extended Client Library](https://github.com/awslabs/amazon-sqs-java-extended-client-lib) Compatibility | ||
## Similarities | ||
* Claim Check structure is identical, i.e. keys are `s3BucketName` and `s3Key`, | ||
meaning you can publish to SQS+S3 via this PHP lib and read via the AWS Extended Client Library java lib. | ||
|
||
## Differences | ||
* Messages published from SNS to SQS contain a nested Claim Check message structure, | ||
so the Java SDK is not be able to natively consume messages published to SNS (really???). | ||
* Usage of the pattern is not configurable by message size, nor can the pattern be disabled in this lib. | ||
Use the wrapped clients if you do not want to use Claim Check. | ||
* The AWS Extended Client Library will always delete the message from S3 when the message is deleted from SQS. | ||
This is not acceptable when messages are published to SNS and fanned-out to multiple subscribers | ||
(e.g. multiple SQS queues). This package allows you to disable deletion from S3 in the SQS extended client | ||
configuration. | ||
|
||
# Installation | ||
``` | ||
composer require abacaphiliac/aws-php-claim-check-sdk | ||
``` | ||
|
||
## Contributing | ||
``` | ||
composer install && vendor/bin/phing | ||
``` | ||
|
||
This library attempts to comply with [PSR-1][], [PSR-2][], and [PSR-4][]. If | ||
you notice compliance oversights, please send a patch via pull request. | ||
|
||
[PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md | ||
[PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md | ||
[PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md | ||
|
||
# Tasks | ||
- [x] Add SQS check-in. | ||
- [x] Add SQS check-out. | ||
- [x] Add SNS check-in. | ||
- [ ] Use WireMock to stub API responses and add feature tests to CI. | ||
- [ ] Add async SQS check-in. | ||
- [ ] Add async SQS check-out. | ||
- [ ] Add async SNS check-in. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
default: | ||
suites: | ||
s3-data-store: | ||
paths: [ %paths.base%/features/s3-data-store ] | ||
contexts: [ AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\S3DataStoreContext ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<project name="abacaphiliac/aws-sdk-php-claim-check" default="develop" basedir="."> | ||
<property name="fixtures" value="wiremock" override="true"/> | ||
|
||
<target name="develop"> | ||
<phingcall target="lint"/> | ||
<phingcall target="tests"/> | ||
</target> | ||
|
||
<target name="lint"> | ||
<phingcall target="php-lint"/> | ||
<phingcall target="phpcs"/> | ||
</target> | ||
|
||
<target name="php-lint"> | ||
<exec command="vendor/bin/parallel-lint src tests" | ||
passthru="true" | ||
output="/dev/stdout" | ||
error="/dev/stdout" | ||
checkreturn="true"/> | ||
</target> | ||
|
||
<target name="phpcs"> | ||
<exec command="vendor/bin/phpcs --standard=PSR2 --extensions=php --severity=1 --colors -p src/ tests/" | ||
passthru="true" | ||
output="/dev/stdout" | ||
error="/dev/stdout" | ||
checkreturn="true"/> | ||
</target> | ||
|
||
<target name="tests"> | ||
<phingcall target="unit-tests"/> | ||
</target> | ||
|
||
<target name="unit-tests"> | ||
<exec command="./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover" | ||
passthru="true" | ||
output="/dev/stdout" | ||
error="/dev/stdout" | ||
checkreturn="true"/> | ||
</target> | ||
|
||
<target name="feature-tests"> | ||
<phingcall target="set-up-feature-fixtures"/> | ||
<exec command="./vendor/bin/behat --colors" | ||
passthru="true" | ||
output="/dev/stdout" | ||
error="/dev/stdout" | ||
checkreturn="true"/> | ||
</target> | ||
|
||
<target name="set-up-feature-fixtures"> | ||
<if> | ||
<equals arg1="${fixtures}" arg2="terraform"/> | ||
<then> | ||
<phingcall target="set-up-terraform-feature-fixtures"/> | ||
</then> | ||
<else> | ||
<phingcall target="set-up-wiremock-feature-fixtures"/> | ||
</else> | ||
</if> | ||
</target> | ||
|
||
<target name="set-up-terraform-feature-fixtures"> | ||
<copy file="features/fixtures/terraform/variables_override.tf.dist" | ||
tofile="features/fixtures/terraform/variables_override.tf.dist" | ||
overwrite="false"/> | ||
<exec command="terraform apply" | ||
dir="features/fixtures/terraform" | ||
passthru="true" | ||
output="/dev/stdout" | ||
error="/dev/stdout" | ||
checkreturn="true"/> | ||
</target> | ||
|
||
<target name="tear-down-terraform-feature-fixtures"> | ||
<exec command="terraform destroy" | ||
dir="features/fixtures/terraform" | ||
passthru="true" | ||
output="/dev/stdout" | ||
error="/dev/stdout" | ||
checkreturn="true"/> | ||
</target> | ||
|
||
<target name="set-up-wiremock-feature-fixtures"> | ||
<fail message="TODO: Boot wiremock daemon and set up stubs."/> | ||
</target> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "abacaphiliac/aws-sdk-php-claim-check", | ||
"description": "Claim Check enterprise integration pattern, implemented via AWS PHP SDK.", | ||
"minimum-stability": "stable", | ||
"license": "proprietary", | ||
"authors": [ | ||
{ | ||
"name": "Timothy Younger", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Abacaphiliac\\AwsSdk\\ClaimCheck\\": "src/ClaimCheck" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"AbacaphiliacFeature\\AwsSdk\\ClaimCheck\\Bootstrap\\": "features/Bootstrap" | ||
} | ||
}, | ||
"require": { | ||
"aws/aws-sdk-php": "^3", | ||
"ramsey/uuid": "^3", | ||
"zendframework/zend-json": "^2" | ||
}, | ||
"require-dev": { | ||
"phing/phing": "^2", | ||
"phpunit/phpunit": "^5|^4", | ||
"behat/behat": "^3", | ||
"vlucas/phpdotenv": "^2", | ||
"ircmaxell/random-lib": "^1", | ||
"jakub-onderka/php-parallel-lint": "^0.9.2", | ||
"squizlabs/php_codesniffer": "^2.6" | ||
}, | ||
"keywords": [ | ||
"aws", | ||
"sdk", | ||
"php", | ||
"claim check", | ||
"enterprise integration pattern", | ||
"sqs", | ||
"sns", | ||
"s3" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait; | ||
|
||
trait AwsConfigContextTrait | ||
{ | ||
/** | ||
* @return mixed[] | ||
*/ | ||
abstract public function overloadEnvironmentVariables(); | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getAwsServiceConfig() | ||
{ | ||
$this->overloadEnvironmentVariables(); | ||
|
||
return [ | ||
'region' => getenv('AWS_REGION') ?: 'us-west-2', | ||
'version' => getenv('AWS_VERSION') ?: 'latest', | ||
'credentials' => [ | ||
'key' => getenv('AWS_KEY') ?: 'foo', | ||
'secret' => getenv('AWS_SECRET') ?: 'bar', | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait; | ||
|
||
use Dotenv\Dotenv; | ||
|
||
trait DotEnvContextTrait | ||
{ | ||
/** | ||
* @return mixed[] | ||
*/ | ||
public function loadEnvironmentVariables() | ||
{ | ||
return $this->createDotEnv()->load(); | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function overloadEnvironmentVariables() | ||
{ | ||
return $this->createDotEnv()->overload(); | ||
} | ||
|
||
/** | ||
* @return Dotenv | ||
*/ | ||
private function createDotEnv() | ||
{ | ||
return new Dotenv(__DIR__ . '/../../../', '.env'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait; | ||
|
||
use Abacaphiliac\AwsSdk\ClaimCheck\ClaimCheckFactory; | ||
use Aws\S3\S3Client; | ||
|
||
trait S3ContextTrait | ||
{ | ||
/** @var string */ | ||
private $bucketName; | ||
|
||
/** @var S3Client */ | ||
private $s3Client; | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
abstract public function getAwsServiceConfig(); | ||
|
||
/** | ||
* @return S3Client | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function getS3Client() | ||
{ | ||
if (!$this->s3Client) { | ||
$config = $this->getAwsServiceConfig(); | ||
|
||
$this->s3Client = new S3Client($config); | ||
} | ||
|
||
return $this->s3Client; | ||
} | ||
|
||
/** | ||
* @Given /^a data store named "([^"]*)"$/ | ||
* @param string $name | ||
* @return string | ||
* @throws \InvalidArgumentException | ||
* @throws \Aws\S3\Exception\S3Exception | ||
* @throws \Exception | ||
*/ | ||
public function getS3BucketFixture($name) | ||
{ | ||
$this->getS3Client()->headBucket(array( | ||
'Bucket' => $name, | ||
)); | ||
|
||
$this->bucketName = $name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getBucketName() | ||
{ | ||
return $this->bucketName; | ||
} | ||
|
||
/** | ||
* @return ClaimCheckFactory | ||
*/ | ||
public function createClaimCheckFactory() | ||
{ | ||
return new ClaimCheckFactory($this->bucketName); | ||
} | ||
} |
Oops, something went wrong.