質問

i use rabbitmq as amqp server(clustering) and kombu+py-amqp as amqp client.i can send/recv message for normal message queue,but i do not know how to send/recv message for mirror queue, and i can not find answers with google .how to send/recv mirror queue message?

my code:

 with Connection(hostname='192.168.1.10',userid='test',password='test',virtual_host='test') as conn:
        simple_queue = conn.SimpleQueue('test')

and get exception

  File "./test_amqp.py", line 38, in send
    simple_queue = conn.SimpleQueue('test')
  File "/usr/local/lib/python3.2/site-packages/kombu/connection.py", line 671, in SimpleQueue
    exchange_opts, **kwargs)
  File "/usr/local/lib/python3.2/site-packages/kombu/simple.py", line 122, in __init__
    consumer = messaging.Consumer(channel, queue)
  File "/usr/local/lib/python3.2/site-packages/kombu/messaging.py", line 338, in __init__
    self.revive(self.channel)
  File "/usr/local/lib/python3.2/site-packages/kombu/messaging.py", line 350, in revive
    self.declare()
  File "/usr/local/lib/python3.2/site-packages/kombu/messaging.py", line 360, in declare
    queue.declare()
  File "/usr/local/lib/python3.2/site-packages/kombu/entity.py", line 471, in declare
    self.queue_declare(nowait, passive=False)
  File "/usr/local/lib/python3.2/site-packages/kombu/entity.py", line 497, in queue_declare
    nowait=nowait)
  File "/usr/local/lib/python3.2/site-packages/amqp/channel.py", line 1240, in queue_declare
    (50, 11),  # Channel.queue_declare_ok
  File "/usr/local/lib/python3.2/site-packages/amqp/abstract_channel.py", line 70, in wait
    return self.dispatch_method(method_sig, args, content)
  File "/usr/local/lib/python3.2/site-packages/amqp/abstract_channel.py", line 88, in dispatch_method
    return amqp_method(self, args)
  File "/usr/local/lib/python3.2/site-packages/amqp/channel.py", line 222, in _close
    (class_id, method_id), ChannelError)
amqp.exceptions.PreconditionFailed: Queue.declare: (406) PRECONDITION_FAILED - inequivalent arg 'x-ha-policy'for queue 'smarton' in vhost 'smarton': received none but current is the value 'all' of type 'longstr'
役に立ちましたか?

解決 2

maybe there is some prolem with kombu,the argument:{"x-ha-policy": "all"} should post to entity.Queue.queue_arguments, but threre is no method of entity.Queue to set the value of entity.Queue.queue_arguments, i changed the kombu.simple.SimpleQueue and get the right result:

112         if not isinstance(queue, entity.Queue):
113             exchange = entity.Exchange(name, 'direct', **exchange_opts)
114             queue = entity.Queue(name, exchange, name, **queue_opts)
115+            queue.queue_arguments={'x-ha-policy':'all'}
116         else:
117             name = queue.name
118             exchange = queue.exchange

他のヒント

When you declare a queue, all of the options have to be identical to the one that already exists on the server. In this case, the server's extra options are 'x-ha-policy': 'all'.

Try simple_queue = conn.SimpleQueue('test', queue_opts={"x-ha-policy": "all"})

I haven't tested this, but I think it'll work.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top