2011年10月15日 星期六

[RabbitMQ] HA on cluster

原來RabbitMQ在使用cluster的時候, 所有的meta都會在所有node各存一份, 除了queue以外, 所以當其中某個node掛掉的時候, 在這個node當中queue裡面的message會全部遺失,

自RabbitMQ 從2.6之後開始support active-active HA, 使用的方法也很簡單, 只需要在declare queue的時候多加"x-ha-policy" 這個argument就可以了.

他是用mirror queue的方式來達到HA的目的, 也就是說, 你可以選擇要把某個queue mirror到哪些其他的nodes.

另外他mirror的方式, 是把master node mirror到其他slave node, 而且要從slave node加進來之後, 他才會開始sync, 之前已經存在master的msg並不會sync.

如果master 掛掉, 他會選擇存在最久的slave node來當作下一個master node.

以目前的2.6.1, "x-ha-policy" 支援兩種方式:

1. all

  把目前的queue之後的message都mirror到cluster裡面其他的所有nodes!

2. nodes

  可以自己選擇要mirror到哪些node, 就算是目前不存在cluster的node也行, mirror會等到那個node加進cluster之後才開始mirror,
  這個需要多加一個參數"x-ha-policy-params", 並把node list 當成value
  !!這個目前有問題, 需要等到下一個release才會修正!!

以下是用pika這個python amqp client API的例子:

    channel.exchange_declare(exchange='test.topic', type='topic')
channel.queue_declare(queue="test_topic", durable=True,
exclusive=False, auto_delete=False,
arguments={'x-ha-policy': 'all'},
callback=on_queue_declared)

Reference:
http://www.rabbitmq.com/ha.html

沒有留言:

張貼留言