8000 feat: add amazon sqs to docs by Simperfit · Pull Request #13328 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

feat: add amazon sqs to docs #13328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
29 changes: 29 additions & 0 deletions messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,35 @@ during a request::
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\KernelTestCase`
or :class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase`.

Amazon SQS
~~~~~~~~~~

.. versionadded:: 5.1

The Amazon SQS transport has been added in Symfony 5.1
Install it by running:

.. code-block:: terminal

$ composer require symfony/amazon-sqs-messenger

The ``SQS`` transport configuration looks like this:

.. code-block:: bash

# .env
MESSENGER_TRANSPORT_DSN=sqs://guest:guest@sqs.eu-west-3.amazonaws.com/test?region=eu-west-3
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
MESSENGER_TRANSPORT_DSN=sqs://guest:guest@sqs.eu-west-3.amazonaws.com/test?region=eu-west-3
MESSENGER_TRANSPORT_DSN=sqs://AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY@sqs.eu-west-3.amazonaws.com/messages
  • use real world credential to help people understanding that credentials are AWS key/secret
  • use a real world queue name
  • remove option region as it's already resolved via the host

Copy link
Member

Choose a reason for hiding this comment

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

I would also add an option to debug with local fake sqs

MESSENGER_TRANSPORT_DSN=sqs://localhost:9494/messages?sslmode=disable

Choose a reason for hiding this comment

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

@jderusse Your example with slashes in the password won't work since it will be parsed by parse_url. So it would be good to add an example using the options.

Suggested change
MESSENGER_TRANSPORT_DSN=sqs://guest:guest@sqs.eu-west-3.amazonaws.com/test?region=eu-west-3
MESSENGER_TRANSPORT_DSN=sqs://sqs.eu-west-3.amazonaws.com/23982323/queue-name

And add this in the example since at least a lot of AWS secrets have slashes in them:

    messenger:
        transports:
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    access_key: "%env(AWS_KEY)%"
                    secret_key: "%env(AWS_SECRET)%"

Copy link
Member

Choose a reason for hiding this comment

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

thanks.

specials char in credentials works but you have to urlencode theme.
indeed my exemple is buggy because of this.

I'd rather keep (and fix) my exemple and add a note about that in the doc. Many people are confused about this.

Choose a reason for hiding this comment

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

A lot of AWS keys will have slashes in them, and I also don't like you have to put your AWS credentials in the .env file multiple times since it's in the DSN in the example.

At least mention this in docs so people don't have to find this out.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. Both ways should be documented.

I like your sample. A little bit more verbose, but avoid missconfiguraiton.
But url_encoding credential is hard to find in the current documentation and should also be documented



.. note::

By default, the transport will automatically create queue that are needed. That can be disabled.
Copy link
Contributor
@noniagriconomie noniagriconomie Mar 10, 2020

Choose a reason for hiding this comment

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

Suggested change
By default, the transport will automatically create queue that are needed. That can be disabled.
By default, the transport will automatically create queues that are needed. This can be disabled using the "auto_setup" option configuration.

or

Suggested change
By default, the transport will automatically create queue that are needed. That can be disabled.
By default, the transport will automatically create queue that is needed. This can be disabled using the "auto_setup" option configuration.

Copy link
Member

Choose a reason for hiding this comment

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

First one is better.


The transport has a number of other options, including ways to configure
the exchange, queues binding keys and more. See the documentation on
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
the exchange, queues binding keys and more. See the documentation on
the exchange, queues binding keys and more. See the code documentation on

:class:`Symfony\\Component\\Messenger\\Transport\\AmazonSqs\\Connection`.

Copy link
Member

Choose a reason for hiding this comment

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

I would define the list of options:

Option Description Default
endpoint Absolute URL to the SQS service https://sqs.eu-west-1.amazonaws.com
region Name of the AWS region  eu-west-1
queue_name Name of the queue messages
account identifier of the AWS account the owner of the credentials
access_key AWS access key
secret_key AWS secret key
buffer_size number of messages to prefetch 9
wait_time long polling duration in seconds 20
poll_timeout wait for new message duration in seconds 0.1
visibility_timeout amount of seconds the message won't be visible queue's configuration
auto_setup Whether the table should be created automatically during send / get. true

and add the note:

difference between `wait_time` and `poll_timeout`: The `wait_time` parameter define 
the maximum duration Amazon SQS should wait until a message is available in a 
queue before sending a response. It helps reducing the cost of using Amazon SQS
by eliminating the number of empty responses.
The `poll_timeout` parameter define the duration the receiver should wait before 
returning null. It avoids blocking other receivers from being called 

and also add:

If the queue name is suffixed by `.fifo` AWS will creates a 
[FIFO queue](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html).
Use the stamp `Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsFifoStamp` 
to define the `Message group ID` and the `Message deduplication ID`.

Choose a reason for hiding this comment

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

another note:

FIFO queues don't support setting a delay per message, for retries to work you need set this to 0 in the config.

retry_strategy:
                    delay: 0 # FIFO queues don't support per-message delay settings

I actually don't know if this should be in the docs or it is a bug :)


Serializing Messages
~~~~~~~~~~~~~~~~~~~~

Expand Down
0