Skip to main content
 首页 » 编程设计

python之如何在 Celery 中传递连接详细信息

2024年10月25日13qq号

我如何使用 Celery 将用户和密码连接详细信息添加到我的代理。我使用的不是 Django 框架,而是 Python 3。

我试过这个:

app = Celery('tasks', 
             broker='sqs://123:123', 
             ) 
 
app.connection( 
    userid="23", 
    password="123", 
    transport_options="{'region': 'eu-west-1'}" 
) 

请您参考如下方法:

您可以使用config_from_object 方法。来自 docs :

Reads configuration from object, where object is either an object or the name of a module to import.

例如:

celeryconfig.py:

BROKER_TRANSPORT = 'amqp' 
BROKER_USER = 'user' 
BROKER_PASSWORD = 'password' 
BROKER_HOST = 'remote.server.com' 
BROKER_PORT = 123 
#... 

在模块中:

app = Celery('tasks') 
app.config_from_object('celeryconfig')