当主节点出现故障时,如何继续接收消息? [RabbitMQ]

时间:2019-06-21 17:42:00

标签: rabbitmq cluster-computing mirroring

我有两台运行RabbitMQ的计算机,分别是Master(ip1)和Slave(ip2),并对其进行了镜像,添加了策略,同步了队列和交换,但是当我发送消息且主服务器掉线时,从服务器停止响应而且我的应用程序无法再发送消息了。

我有一个虚拟主机,持久的队列和交换,这是一个提升从属的策略。

政策

Pattern             ^test
Apply to            all
Definition  
ha-mode:            exactly
ha-params:          5
ha-promote-on-failure:  always
ha-promote-on-shutdown: always
ha-sync-mode:           automatic
queue-master-locator:   random
Priority            0

这是我用来发布消息的应用程序(编辑:RabbitMQ UI上已经设置了队列)

import pika
import time

credentials = pika.PlainCredentials('usr', 'pass')

parameters = pika.ConnectionParameters('ip1',
                                       5672,
                                       'virtual_host',
                                       credentials)

connection = pika.BlockingConnection(parameters)

channel = connection.channel()

channel.exchange_declare(
    exchange="test_exchange",
    exchange_type="direct",
    passive=False,
    durable=True,
    auto_delete=False)

##channel.queue_declare(queue='test', durable=True, exclusive=False, auto_delete=False)

input('Press ENTER to begin')

for i in range(10000):
    channel.basic_publish(exchange='',
                      routing_key='test',
                      body=('Hello World! '+ str(i)))
    time.sleep(0.001)
print(" [x] Sent 'Hello World!'")

我希望当主服务器出现故障时,从服务器会被提升并接收消息。

0 个答案:

没有答案