通过Spring集成和RabbitMQ提供高度可用的AMQP
我做了什么:
我正在使用RabbitMQ消息代理,它在我的弹簧微服务中支持AMQP标准。 它的主要目的是在rabbitMQ服务器(不幸)关闭期间防止消息丢失。 所以我打算给高度可用的AMQP支持消息频道。
我尝试安装两个RabbitMQ服务器,然后按照以下链接安装RabbitMQ服务器。
https://dzone.com/articles/highly-available-amqp-backed
第一个RabbitMQ服务器的配置文件(rabbitmq.config)如下。 它应该放在../rabbitmq_server-version/etc/rabbitmq/
[
{rabbit, [ {tcp_listeners, [5672]},
{collect_statistics_interval, 10000},
{heartbeat,30},
{cluster_partition_handling, pause_minority},
{cluster_nodes, {[ 'rabbit@master',
'rabbit2@master'],
disc}} ] },
{rabbitmq_management, [ {http_log_dir,"/tmp/rabbit-mgmt"},{listener, [{port, 15672}]} ] },
{rabbitmq_management_agent, [ {force_fine_statistics, true} ] }
].
第二个RabbitMQ服务器的rabbitmq.config文件:
[
{rabbit, [ {tcp_listeners, [5673]},
{collect_statistics_interval, 10000},
{heartbeat,30},
{cluster_partition_handling, pause_minority},
{cluster_nodes, {[ 'rabbit@master',
'rabbit2@master'],
disc}} ] },
{rabbitmq_management, [ {http_log_dir,"/tmp/rabbit-mgmt"},{listener, [{port, 15673}]} ] },
{rabbitmq_management_agent, [ {force_fine_statistics, true} ] }
].
第一个RabbitMQ服务器的示例bash脚本如下。 另请查看RabbitMQ Cluster文档了解其他配置步骤。
#!/bin/bash
echo "*** First RabbitMQ Server is setting up ***"
export RABBITMQ_HOSTNAME=rabbit@master
export RABBITMQ_NODE_PORT=5672
export RABBITMQ_NODENAME=rabbit@master
export RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15672}]"
/DEV_TOOLS/rabbitmq_server-3.4.2/sbin/rabbitmq-server &
echo "*** Second RabbitMQ Server is set up succesfully. ***"
sleep 5
echo "*** First RabbitMQ Server' s status : ***"
/DEV_TOOLS/rabbitmq_server-3.4.2/sbin/rabbitmqctl status
第二个RabbitMQ服务器的示例bash脚本如下:
#!/bin/bash
echo "*** Second RabbitMQ Server is setting up ***"
export RABBITMQ_HOSTNAME=rabbit2@master
export RABBITMQ_NODE_PORT=5673
export RABBITMQ_NODENAME=rabbit2@master
export RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}]"
/DEV_TOOLS/rabbitmq_server-3.4.2_2/sbin/rabbitmq-server &
echo "*** Second RabbitMQ Server is set up succesfully. ***"
sleep 5
echo "*** Second RabbitMQ Server' s status : ***"
/DEV_TOOLS/rabbitmq_server-3.4.2_2/sbin/rabbitmqctl status
sleep 5
echo "*** Second RabbitMQ Server is being added to cluster... ***"
/DEV_TOOLS/rabbitmq_server-3.4.2_2/sbin/rabbitmqctl -n rabbit2@master stop_app
/DEV_TOOLS/rabbitmq_server-3.4.2_2/sbin/rabbitmqctl -n rabbit2@master join_cluster rabbit@master
/DEV_TOOLS/rabbitmq_server-3.4.2_2/sbin/rabbitmqctl -n rabbit2@master start_app
/DEV_TOOLS/rabbitmq_server-3.4.2/sbin/rabbitmqctl -n rabbit@master set_policy ha-all "^ha." '{"ha-mode":"all"}'
echo "*** Second RabbitMQ Server is added to cluster successfully... ***"
sleep 5
echo "*** Second RabbitMQ Server' s cluster status : ***"
/DEV_TOOLS/rabbitmq_server-3.4.2_2/sbin/rabbitmqctl cluster_status
什么是问题:
我可以看到两个RabbitMQ服务器正在同步运行。
当我停止第一个节点时,第二个节点正在工作。
sbin/rabbitmqctl stop_app
但是当我关闭第一台RabbitMQ服务器时,第二个节点也停止运行。
sbin/rabbitmqctl stop
但是,结果应该是,
如果第一个消息传递节点和第一个RabbitMQ服务器意外关闭,第二个消息传递节点和第二个RabbitMQ服务器将继续处理订单消息,因此可以通过使用高可用性AMQP支持的通道来防止潜在的消息丢失和服务中断问题。
请帮我解决这个问题。 谢谢。
链接地址: http://www.djcxy.com/p/34105.html上一篇: Highly Available AMQP via Spring Integration and RabbitMQ