Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Make sure we can work with FIFO #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This guide assumes that:
- Symfony Messenger is installed
- Bref is installed and [configured to deploy Symfony](https://bref.sh/docs/frameworks/symfony.html)
- a SQS queue has already been created
- (If FIFO queue, then enable "Content-Based Deduplication")

First, install this package:

Expand All @@ -32,7 +33,10 @@ Next, configure Symfony Messenger to dispatch a message via SQS:
framework:
messenger:
transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
async:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
# If FIFO queue, you must add message_group_id.
options: { message_group_id: com_example }
routing:
'App\Message\MyMessage': async
```
Expand Down
9 changes: 8 additions & 1 deletion src/Sqs/SqsTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ class SqsTransport implements TransportInterface
private $sqs;
/** @var string */
private $queueUrl;
/** @var string|null */
private $messageGroupId;

public function __construct(SqsClient $sqs, ?SerializerInterface $serializer, string $queueUrl)
public function __construct(SqsClient $sqs, ?SerializerInterface $serializer, string $queueUrl, ?string $messageGroupId)
{
$this->sqs = $sqs;
$this->serializer = $serializer ?? new PhpSerializer;
$this->queueUrl = $queueUrl;
$this->messageGroupId = $messageGroupId;
}

public function send(Envelope $envelope): Envelope
Expand All @@ -43,6 +46,10 @@ public function send(Envelope $envelope): Envelope
'QueueUrl' => $this->queueUrl,
];

if ($this->messageGroupId !== null) {
$arguments['MessageGroupId'] = $this->messageGroupId;
}

try {
$result = $this->sqs->sendMessage($arguments);
} catch (Throwable $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/Sqs/SqsTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(SqsClient $sqs, ?SerializerInterface $serializer = n

public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
{
return new SqsTransport($this->sqs, $this->serializer, $dsn);
return new SqsTransport($this->sqs, $this->serializer, $dsn, $options['message_group_id'] ?? null);
}

public function supports(string $dsn, array $options): bool
Expand Down