cassandra ValueError: contact_points, endpoint_factory, ssl_context, and ssl_options cannot be specified with a cloud configuration

Viewed 50

I am new to cassandra and trying to use it with celery task queue.

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

when I send jobs to celery worker I get the below error

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

I can connect to the cassandra cluster as below without any issue

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()

can someone suggest how to use cassandra correctly with celery?

1 Answers

You can find a walkthrough to connect Celery to Datastax Astra here

This is what your configuration should look like

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
Related