Kombu & celery with SQS #222 (#1779)

* + celery with sqs #222

* Update docs/userguide/connections.rst

* Update docs/userguide/connections.rst

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>

* Update docs/userguide/connections.rst

* Update docs/userguide/connections.rst

* Update docs/userguide/connections.rst

---------

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
This commit is contained in:
Mohd Shoaib 2023-08-31 13:44:57 +05:30 committed by GitHub
parent 492776eb7f
commit a4efb9c17f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 1 deletions

View File

@ -66,6 +66,34 @@ resources:
.. _connection-urls:
Celery with SQS
===============
SQS broker url doesn't include queue_name_prefix by default.
So we can use the following code snippet to make it work in celery.
.. code-block:: python
from celery import Celery
def make_celery(app):
celery = Celery(
app.import_name,
broker="sqs://",
broker_transport_options={
"queue_name_prefix": "{SERVICE_ENV}-{SERVICE_NAME}-"
},
)
task_base = celery.Task
class ContextTask(task_base):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return task_base.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
URLs
====
@ -88,7 +116,7 @@ All of these are valid URLs:
# Using Redis over a Unix socket
redis+socket:///tmp/redis.sock
# Using Redis sentinel
sentinel://sentinel1:26379;sentinel://sentinel2:26379