我是cassandra的新手,正在尝试将它与芹菜任务队列一起使用。
import json
from cassandra.auth import PlainTextAuthProvider
from celery import Celery
from config_constant import REDIS_CONNECTION
app = Celery('tasks', broker=REDIS_CONNECTION,
result_backend='cassandra',
result_extended=True)
cassandra_options = {
'cloud': {
'secure_connect_bundle': 'path/to/astra-secure-connect.zip'
}
}
client_id_config = json.load(open('path/to/client_id_secret.json'))
app.conf.update(
cassandra_options=cassandra_options,
cassandra_keyspace='my_keyspace',
cassandra_table='my_table',
cassandra_servers=['myserver.db.astra.datastax.com:29080'],
cassandra_auth_provider=PlainTextAuthProvider(client_id_config['client_id'], client_id_config['client_secret'])
)
@app.task
def repeated_squaring(x: int, y: int):
power = 1
while y:
power = power * x * x
if x % 2 != 0:
power *= x
y //= 2
return x, y, power
当我发送作业到celery worker时,我得到下面的错误
File "cassandra/cluster.py", line 1120, in cassandra.cluster.Cluster.__init__
ValueError: contact_points, endpoint_factory, ssl_context, and ssl_options cannot be specified with a cloud configuration
我可以像下面这样连接到cassandra集群,没有任何问题
cloud_config = {
'secure_connect_bundle': 'path/to/astra-secure-connect.zip'
}
client_id_config = json.load(open('path/to/client_id_secret.json'))
auth_provider = PlainTextAuthProvider(client_id_config['client_id'], client_id_config['client_secret'])
cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
session = cluster.connect()
谁能建议如何正确地使用卡桑德拉和芹菜?
您可以在这里找到连接芹菜到Datastax Astra的指南
你的配置应该是这样的
broker_url = 'pyamqp://guest@localhost//'
broker_connection_retry_on_startup = True
task_serializer = 'json'
result_serializer = 'json'
accept_content = ['json']
enable_utc = True
result_backend = 'cassandra://'
cassandra_keyspace = 'celeryks' # REPLACE_ME
cassandra_table = 'celery_tasks' # REPLACE_ME
cassandra_read_consistency = 'quorum'
cassandra_write_consistency = 'quorum'
cassandra_auth_provider = 'PlainTextAuthProvider'
cassandra_auth_kwargs = {
'username': 'client-id-from-astra-token', # REPLACE_ME
'password': 'client-secret-from-astra-token', # REPLACE_ME
}
cassandra_secure_bundle_path = '/path/to/secure-connect-database.zip' # REPLA