sqs.rst 4.7 KB

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