Cassandra valueError:contact_points,endpoint_factory,ssl_context和ssl_options不能使用云配置指定

发布于 2025-01-29 05:22:23 字数 1710 浏览 4 评论 0原文

我是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

当我将作业发送给芹菜工人时,我会收到以下错误,

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

有人可以建议如何与芹菜正确使用Cassandra吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

财迷小姐 2025-02-05 05:22:23

您可以找到一项演练,可以将芹菜连接到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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文