weixin_39775127
weixin_39775127
2020-12-08 18:37

auto_delete argument to Exchange only works with pyamqp

Trying to track down a problem where the same rabbitmq Exchange declaration, imported into two separate programs, was throwing a 406 PRECONDITION_FAILED error. It turns out that since one of them was using gevent, it was using pyamqp. The other was using librabbitmq. And for some reason, librabbitmq seems to be ignoring the auto_delete argument.


exchange = Exchange('exchange_test', type='fanout',
                    auto_delete=True, delivery_mode='transient', durable=False)
queue = Queue('queue_test_{}'.format(uuid.uuid4().hex),
              exchange, durable=False, auto_delete=True, no_ack=True)

with Connection('amqp://guest:guest:5672//') as connection:
    try:
        with connection.Consumer(queues=queue, callbacks=[print_body],
                                 no_ack=True, auto_declare=True) as consumer:
            consumer.consume(no_ack=True)
            connection.drain_events()

该提问来源于开源项目:celery/kombu

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39640883 weixin_39640883 5月前

    Right, the rabbitmq-c library removed support of auto_delete for reasons unknown as it was previously supported. Not sure what the python client can do about it :/

    点赞 评论 复制链接分享
  • weixin_39640883 weixin_39640883 5月前

    This should shed some light on this: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2011-July/013708.html

    So the auto_delete argument to exchange_declare was removed in AMQP 0.9.1, which means that py-amqp should deprecate it (we cannot just remove it for backwards compatibility).

    点赞 评论 复制链接分享
  • weixin_39640883 weixin_39640883 5月前

    Oh, auto_delete is already deprecated in amqp but the warning is a normal DeprecationWarning so is not seen in program output. I will replace that with a custom deprecation warning class so that users will actually see it.

    点赞 评论 复制链接分享
  • weixin_39775127 weixin_39775127 5月前

    Makes sense. Thanks for the explanation!

    点赞 评论 复制链接分享

相关推荐