Amazon SQS Support
Ecotone support for Amazon SQS PHP
Installation
composer require ecotone/sqsModule Powered By
Enqueue solid and powerful abstraction over asynchronous queues.
Configuration
In order to use SQS Support we need to add ConnectionFactory to our Dependency Container.
# config/services.yaml
Enqueue\Sqs\SqsConnectionFactory:
class: Enqueue\Sqs\SqsConnectionFactory
arguments:
- "sqs:?key=key&secret=secret®ion=us-east-1&version=latest"use Enqueue\Sqs\SqsConnectionFactory;
public function register()
{
$this->app->singleton(SqsConnectionFactory::class, function () {
return new SqsConnectionFactory("sqs:?key=key&secret=secret®ion=us-east-1&version=latest");
});
}use Enqueue\Sqs\SqsConnectionFactory;
$application = EcotoneLiteApplication::boostrap(
[
SqsConnectionFactory::class => new SqsConnectionFactory("sqs:?key=key&secret=secret®ion=us-east-1&version=latest")
]
);Message Channel
To create Message Channel, we need to create Service Context.
use Ecotone\Sqs\SqsBackedMessageChannelBuilder;
class MessagingConfiguration
{
#[ServiceContext]
public function orderChannel()
{
return SqsBackedMessageChannelBuilder::create("orders");
}
}Now orders channel will be available in Messaging System.
Message Channel Configuration
High Throughput Publishing (Enterprise)
Messages published within the same execution scope can be combined into SQS batch requests with overlapping in-flight deliveries, multiplying publishing throughput:
Both mechanisms can be tuned individually with batchPublishing, nonBlockingConfirmation and confirmationTimeoutInMilliseconds.
Read more in Non-blocking Batched Delivery.
Message Publisher
If you want to publish Message directly to Exchange, you may use of Publisher.
Reference name- Name under which it will be available in Dependency Container.Queue name- Name of queue where Message should be publishedDefault Conversion [Optional]- Default type, payload will be converted to.
Publisher Configuration
withAutoDeclareQueueOnSend- should Ecotone try to declare queue before sending messagewithHeaderMapper- On default headers are not send with message. You map provide mapping for headers that should be mapped toSQS Message
Message Consumer
To connect consumer directly to a SQS Queue, we need to provide Ecotone with information, how the Queue is configured.
Provides Consumer that will be registered at given name
"orders_consumer"and will be polling"orders"queue
Consumer Configuration
Materials
Demo implementation
Links
Last updated
Was this helpful?