How to connect celery to rabbitMQ using SSL

末鹿安然 提交于 2020-01-03 05:14:06

问题


I'm trying to connect celery with a rabbitMQ broker using SSL certificates.

This is the code:

from celery import Celery
import ssl

broker_uri = 'amqp://user:pwd@server:5672/vhost'

certs_conf = {
    "ca_certs": "/certs/serverca/cacert.pem",
    "certfile": "/certs/client/rabbit-cert.pem",
    "keyfile": "/certs/client/rabbit-key.pem",
    "cert_reqs": ssl.CERT_REQUIRED
}

app = Celery('tasks', broker=broker_uri)
app.conf.update(BROKER_USE_SSL=certs_conf)

app.send_task('task.name', [{'a': 1}])

When I try to execute this code i get the following exception:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\kombu\utils\functional.py", line 36, in __call__
    return self.__value__
AttributeError: 'ChannelPromise' object has no attribute '__value__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_send_task.py", line 44, in <module>
    app.send_task('task.name', [message])
  File "C:\Python36\lib\site-packages\celery\app\base.py", line 737, in send_task
    amqp.send_task_message(P, name, message, **options)
  File "C:\Python36\lib\site-packages\celery\app\amqp.py", line 558, in send_task_message
    **properties
  File "C:\Python36\lib\site-packages\kombu\messaging.py", line 181, in publish
    exchange_name, declare,
  File "C:\Python36\lib\site-packages\kombu\connection.py", line 494, in _ensured
    return fun(*args, **kwargs)
  File "C:\Python36\lib\site-packages\kombu\messaging.py", line 187, in _publish
    channel = self.channel
  File "C:\Python36\lib\site-packages\kombu\messaging.py", line 209, in _get_channel
    channel = self._channel = channel()
  File "C:\Python36\lib\site-packages\kombu\utils\functional.py", line 38, in __call__
    value = self.__value__ = self.__contract__()
  File "C:\Python36\lib\site-packages\kombu\messaging.py", line 224, in <lambda>
    channel = ChannelPromise(lambda: connection.default_channel)
  File "C:\Python36\lib\site-packages\kombu\connection.py", line 819, in default_channel
    self.ensure_connection()
  File "C:\Python36\lib\site-packages\kombu\connection.py", line 405, in ensure_connection
    callback)
  File "C:\Python36\lib\site-packages\kombu\utils\functional.py", line 333, in retry_over_time
    return fun(*args, **kwargs)
  File "C:\Python36\lib\site-packages\kombu\connection.py", line 261, in connect
    return self.connection
  File "C:\Python36\lib\site-packages\kombu\connection.py", line 802, in connection
    self._connection = self._establish_connection()
  File "C:\Python36\lib\site-packages\kombu\connection.py", line 757, in _establish_connection
    conn = self.transport.establish_connection()
  File "C:\Python36\lib\site-packages\kombu\transport\pyamqp.py", line 130, in establish_connection
    conn.connect()
  File "C:\Python36\lib\site-packages\amqp\connection.py", line 288, in connect
    self.drain_events(timeout=self.connect_timeout)
  File "C:\Python36\lib\site-packages\amqp\connection.py", line 471, in drain_events
    while not self.blocking_read(timeout):
  File "C:\Python36\lib\site-packages\amqp\connection.py", line 477, in blocking_read
    return self.on_inbound_frame(frame)
  File "C:\Python36\lib\site-packages\amqp\method_framing.py", line 55, in on_frame
    callback(channel, method_sig, buf, None)
  File "C:\Python36\lib\site-packages\amqp\connection.py", line 481, in on_inbound_method
    method_sig, payload, content,
  File "C:\Python36\lib\site-packages\amqp\abstract_channel.py", line 128, in dispatch_method
    listener(*args)
  File "C:\Python36\lib\site-packages\amqp\connection.py", line 368, in _on_start
    b", ".join(self.mechanisms).decode()))
amqp.exceptions.ConnectionError: Couldn't find appropriate auth mechanism (can offer: AMQPLAIN, PLAIN; available: EXTERNAL)

Executing the same code without the ssl configuration works just well. What I'm missing?

I can send messages to the broker using pika configured with SSL, but I can't manage to properly configure Celery to send messages to the same broker with SSL.

Thanks in advance.


回答1:


Try using the setting:

broker_use_ssl=True

You can also use the broker url starting with amqps://...



来源:https://stackoverflow.com/questions/49320158/how-to-connect-celery-to-rabbitmq-using-ssl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!