pmg / sqs-transport
A Symfony Messenger transport for SQS
Installs: 40 482
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 14
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- aws/aws-sdk-php: ^3.288
- symfony/messenger: ^5.4.35 || ^6.4
Requires (Dev)
- aws/aws-sdk-php-symfony: ^2.7
- guzzlehttp/guzzle: ^7.8
- phpunit/phpunit: ^9.5
- symfony/framework-bundle: ^5.4.35 || ^6.4
- symfony/phpunit-bridge: ^5.4.35 || ^6.4
- symfony/property-access: ^5.4.35 || ^6.4
- symfony/serializer: ^5.4.35 || ^6.4
- symfony/yaml: ^5.4.35 || ^6.4
README
⚠️ DEPRECATION NOTICE: This project is no longer maintained and might not work as expected. Use Alli Platform Bundle instead. Check this migration guide for more information: Migrating from PMG SQS Transport to Alli Platform Bundle
Installation
composer require pmg/sqs-transport
Bundle Usage
Add the PMG\SqsTransport\Bundle\PmgSqsTransportBundle
to your application's
kernel. By default the transport bundle will use an aws.sqs
service when
creating the transport factory and, by extension, the transport instances.
This service name is configurable, but it should place nice with the AWS
Bundle.
class AppKernel extends Kernel { // ... public function registerBundles() { $bundles = [ new \Aws\Symfony\AwsBundle(), new \PMG\SqsTransport\Bundle\PmgSqsTransportBundle(), ]; // ... return $bundles; } }
SqsClient
Service Configuration
If you're not using the AwsBundle
and would like to manually specify a service
that contains an instance of Aws\Sqs\SqsClient
, some bundle configuration is
necessary.
pmg_sqs_transport: sqs_client_service: your_sqs_service_id
Messenger Configuration
framework: # ... messenger: transports: # will create a transport with a queue URL of # https://queue.amazonaws.com/80398EXAMPLE/MyQueue sqs: sqs://queue.amazonaws.com/80398EXAMPLE/MyQueue # this will also make an https URL: # https://queue.amazonaws.com/80398EXAMPLE/MyQueue sqs_https: sqs+https://queue.amazonaws.com/80398EXAMPLE/MyQueue # or you may wish to use `http://`, like if running a localstack # instance for local dev. Queue url would be http://localhost:4576/queue/MyQueue sqs_http: sqs+http://localhost:4576/queue/MyQueue # specify how many message to receive at once with query params # must be >= 1 and <= 10 sqs: sqs://queue.amazonaws.com/80398EXAMPLE/MyQueue?receive_count=10 # specify a wait timeout when making a call to receive messages (in seconds) sqs: sqs://queue.amazonaws.com/80398EXAMPLE/MyQueue?receive_wait=10 # or specify those things in `options` sqs: dsn: sqs://queue.amazonaws.com/80398EXAMPLE/MyQueue options: receive_wait: 10 receive_count: 5
SQS Stamps
PMG\SqsTransport\Stamp\SqsReceiptHandleStamp
: added when a message is received from SQS via theget
method. This allows the message to beack
ed orreject
ed later.PMG\SqsTransport\Stamp\SqsStringAttributeStamp
: Allows you to add a custom message attribute. with aDataType
set toString
and a string value.PMG\SqsTransport\Stamp\SqsNumberAttributeStamp
: Allows you to add a custom message attribute. with aDataType
set toNumber
and a numeric value.
$messageBus->dispatch(new YourMessage(), [ new SqsStringAttributeStamp('stringAttributeName', 'attributeValue'), new SqsNumberAttributeStamp('numberAttributeName', 123), ]);
SQS Has a limit of 10 attributes per message, but the transport will
generally use at least one attribute to send the headers
from the transport
serializer.
On Retries
The symfony messenger worker modifies an envelope with some retry metadata.
Since messages in SQS cannot be modified in place, we just put a new message
into the queue when that happens and the subsequent call to ack
removes the
existing message.