Skip to content

Conversation

@Greg0
Copy link

@Greg0 Greg0 commented Oct 15, 2025

Q A
Branch? 8.1
Bug fix? no
New feature? yes
Deprecations? no
Issues Feature #61946
License MIT

What it does and why it's needed

This PR adds support for AWS SQS fair queues by introducing a new AmazonSqsFairQueueStamp. Fair queues allow messages to be processed fairly across multiple message groups without requiring a FIFO queue, which is useful for multi-tenant applications where you want to prevent one tenant from monopolizing queue processing.

According to the AWS SQS fair queues documentation, you can achieve fair processing in standard queues by setting the MessageGroupId parameter without converting to a FIFO queue.

How it works

Add the AmazonSqsFairQueueStamp to your message envelope with a tenant/group identifier:

use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsFairQueueStamp;

$envelope = new Envelope($message, [
    new AmazonSqsFairQueueStamp('tenant-123'),
]);

$messageBus->dispatch($envelope);

The stamp sets the MessageGroupId parameter on standard SQS queues, enabling fair message distribution across different message groups without the overhead of FIFO queues.

Important notes

  • The AmazonSqsFairQueueStamp only works on standard queues (not FIFO)
  • If both AmazonSqsFifoStamp and AmazonSqsFairQueueStamp are present, the FIFO stamp takes precedence

Changes

  • Added AmazonSqsFairQueueStamp class
  • Modified AmazonSqsSender to handle the fair queue stamp
  • Updated Connection to support MessageGroupId on standard queues
  • Added comprehensive test coverage
  • Updated CHANGELOG

@carsonbot carsonbot added this to the 7.4 milestone Oct 15, 2025
@carsonbot carsonbot changed the title [Messenger] [Sqs] Add SQS fair queues support [Messenger][Sqs] Add SQS fair queues support Oct 15, 2025
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@Greg0 Greg0 force-pushed the messenger-amazon-sqs-fair-queues branch 2 times, most recently from 647513b to 606e30d Compare October 18, 2025 07:04
@Greg0
Copy link
Author

Greg0 commented Oct 18, 2025

Branch rebased, commits squashed.

@Greg0 Greg0 force-pushed the messenger-amazon-sqs-fair-queues branch from 606e30d to af21de9 Compare October 26, 2025 19:55
@Greg0
Copy link
Author

Greg0 commented Oct 26, 2025

Rebased. Still waiting for review

@GrzegorzDrozd
Copy link

Hi @Greg0 !

Is there a chance for you to target 6.4?

Thanks and have a good day!

@Greg0
Copy link
Author

Greg0 commented Nov 8, 2025

@GrzegorzDrozd AFAIR features can be proposed only for future releases. That one will target probably nearest v8.1

7.4 and 8.0 are in RC stage

@GrzegorzDrozd
Copy link

@GrzegorzDrozd AFAIR features can be proposed only for future releases. That one will target probably nearest v8.1

7.4 and 8.0 are in RC stage

What if we threat this as a bug. In fact code prevents you from sending message using a fair queue mechanism.

@Greg0
Copy link
Author

Greg0 commented Nov 9, 2025

@GrzegorzDrozd AFAIR features can be proposed only for future releases. That one will target probably nearest v8.1

7.4 and 8.0 are in RC stage

What if we threat this as a bug. In fact code prevents you from sending message using a fair queue mechanism.

I would say code just not supports it instead of supporting it in wrong way (bug). AWS introduced that in Q2 2025 so it's new feature in SQS itself.

Docs about contributing describes clearly what is what.
I want and need that change in my daily work too 😊

There is always possibility of forking messenger SQS lib and applying such changes in private scope.

@Greg0
Copy link
Author

Greg0 commented Nov 27, 2025

Symfony docs update
symfony/symfony-docs#21598

@Greg0 Greg0 force-pushed the messenger-amazon-sqs-fair-queues branch from 4a92031 to 28f9e03 Compare December 7, 2025 10:02
Copy link
Member

@stof stof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether we should throw an exception when both the Fifo and Fair stamps are set instead of silently ignoring the Fair stamp.

And the readme of the bridge should document that bridge-specific stamp (symfony-docs currently does not have dedicated documentation pages for each platform bridge)

$messageDeduplicationId = $amazonSqsFifoStamp->getMessageDeduplicationId();
}

/** @var AmazonSqsFairQueueStamp|null $amazonSqsFairQueueStamp */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed. The generic types on the last method already infer the same type for that variable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, removed

@Greg0
Copy link
Author

Greg0 commented Dec 15, 2025

I'm wondering whether we should throw an exception when both the Fifo and Fair stamps are set instead of silently ignoring the Fair stamp.

And the readme of the bridge should document that bridge-specific stamp (symfony-docs currently does not have dedicated documentation pages for each platform bridge)

Would you like me to place change that will throw exception in that specific case? I do not have strong arguments to follow any of proposed paths (silent ignore or exception throwing). Exception make sense because it's not expected to use that both stamps and the same time.

@Greg0
Copy link
Author

Greg0 commented Dec 17, 2025

@stof Actually, after thinking about this more carefully, I believe keeping the silent precedence is the better approach.
Here's why:
The AmazonSqsFifoStamp is often added automatically by the transport layer when it detects a .fifo queue suffix (which is forced by AWS). In multi-tenant applications, it's common to have middleware that could automatically add AmazonSqsFairQueueStamp globally to all messages for tenant isolation.

This creates a practical conflict: if we throw an exception when both stamps are present, it would force developers to add complex conditional logic in their middleware to check queue types before adding the fair queue stamp. This is particularly problematic because:

  • Middleware typically doesn't have visibility into the transport configuration or queue naming
  • It would break the composability of stamps and middleware

The current behavior (FIFO taking precedence) is actually the correct AWS behavior - FIFO queues already guarantee ordering and uses the same MessageGroupId attribute internally, so the fair queue stamp would be redundant anyway.

If we want to be more explicit, we could:

  • Add a debug log when both stamps are present and FIFO takes precedence
  • Document this behavior clearly in the stamp's docblock

But throwing an exception would make the feature harder to use in real-world scenarios where automatic stamp application is needed.

What do you think?

@Greg0
Copy link
Author

Greg0 commented Dec 17, 2025

And the readme of the bridge should document that bridge-specific stamp (symfony-docs currently does not have dedicated documentation pages for each platform bridge)

@stof I've updated bridge readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants