sqs.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. .. _broker-sqs:
  2. ==================
  3. Using Amazon SQS
  4. ==================
  5. .. _broker-sqs-installation:
  6. Installation
  7. ============
  8. For the Amazon SQS support you have to install the :pypi:`boto`
  9. library using :command:`pip`:
  10. .. code-block:: console
  11. $ pip install -U boto
  12. .. _broker-sqs-configuration:
  13. Configuration
  14. =============
  15. You have to specify SQS in the broker URL::
  16. broker_url = 'sqs://ABCDEFGHIJKLMNOPQRST:ZYXK7NiynGlTogH8Nj+P9nlE73sq3@'
  17. where the URL format is:
  18. .. code-block:: text
  19. sqs://aws_access_key_id:aws_secret_access_key@
  20. you must *remember to include the "@" at the end*.
  21. The login credentials can also be set using the environment variables
  22. :envvar:`AWS_ACCESS_KEY_ID` and :envvar:`AWS_SECRET_ACCESS_KEY`,
  23. in that case the broker URL may only be ``sqs://``.
  24. If you are using IAM roles on instances, you can set the BROKER_URL to:
  25. ``sqs://`` and kombu will attempt to retrive access tokens from the instance
  26. metadata.
  27. .. note::
  28. If you specify AWS credentials in the broker URL, then please keep in mind
  29. that the secret access key may contain unsafe characters that needs to be
  30. URL encoded.
  31. Options
  32. =======
  33. Region
  34. ------
  35. The default region is ``us-east-1`` but you can select another region
  36. by configuring the :setting:`broker_transport_options` setting::
  37. broker_transport_options = {'region': 'eu-west-1'}
  38. .. seealso::
  39. An overview of Amazon Web Services regions can be found here:
  40. http://aws.amazon.com/about-aws/globalinfrastructure/
  41. Visibility Timeout
  42. ------------------
  43. The visibility timeout defines the number of seconds to wait
  44. for the worker to acknowledge the task before the message is redelivered
  45. to another worker. Also see caveats below.
  46. This option is set via the :setting:`broker_transport_options` setting::
  47. broker_transport_options = {'visibility_timeout': 3600} # 1 hour.
  48. The default visibility timeout is 30 seconds.
  49. Polling Interval
  50. ----------------
  51. The polling interval decides the number of seconds to sleep between
  52. unsuccessful polls. This value can be either an int or a float.
  53. By default the value is *one second*: this means the worker will
  54. sleep for one second when there's no more messages to read.
  55. You must note that **more frequent polling is also more expensive, so increasing
  56. the polling interval can save you money**.
  57. The polling interval can be set via the :setting:`broker_transport_options`
  58. setting::
  59. broker_transport_options = {'polling_interval': 0.3}
  60. Very frequent polling intervals can cause *busy loops*, resulting in the
  61. worker using a lot of CPU time. If you need sub-millisecond precision you
  62. should consider using another transport, like `RabbitMQ <broker-amqp>`,
  63. or `Redis <broker-redis>`.
  64. Queue Prefix
  65. ------------
  66. By default Celery won't assign any prefix to the queue names,
  67. If you have other services using SQS you can configure it do so
  68. using the :setting:`broker_transport_options` setting::
  69. broker_transport_options = {'queue_name_prefix': 'celery-'}
  70. .. _sqs-caveats:
  71. Caveats
  72. =======
  73. - If a task isn't acknowledged within the ``visibility_timeout``,
  74. the task will be redelivered to another worker and executed.
  75. This causes problems with ETA/countdown/retry tasks where the
  76. time to execute exceeds the visibility timeout; in fact if that
  77. happens it will be executed again, and again in a loop.
  78. So you have to increase the visibility timeout to match
  79. the time of the longest ETA you're planning to use.
  80. Note that Celery will redeliver messages at worker shutdown,
  81. so having a long visibility timeout will only delay the redelivery
  82. of 'lost' tasks in the event of a power failure or forcefully terminated
  83. workers.
  84. Periodic tasks won't be affected by the visibility timeout,
  85. as it is a concept separate from ETA/countdown.
  86. The maximum visibility timeout supported by AWS as of this writing
  87. is 12 hours (43200 seconds)::
  88. broker_transport_options = {'visibility_timeout': 43200}
  89. - SQS doesn't yet support worker remote control commands.
  90. - SQS doesn't yet support events, and so cannot be used with
  91. :program:`celery events`, :program:`celerymon`, or the Django Admin
  92. monitor.
  93. .. _sqs-results-configuration:
  94. Results
  95. -------
  96. Multiple products in the Amazon Web Services family could be a good candidate
  97. to store or publish results with, but there's no such result backend included
  98. at this point.
  99. .. warning::
  100. Don't use the ``amqp`` result backend with SQS.
  101. It will create one queue for every task, and the queues will
  102. not be collected. This could cost you money that would be better
  103. spent contributing an AWS result store backend back to Celery :)