RabbitMQ(10)Update Version and Cluster Configuration
RabbitMQ(10)Update Version and Cluster Configuration
1. Installation and Update Check
Check the erlang version first
>erl -version
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 5.10.4
I have the rabbitmq here rabbitmq -> /opt/rabbitmq-3.1.5
Message Acknowledgment
Message acknowledgments are turned on by default. autoAck=true flag will turned them off.
boolean autoAck = false;
channel.basicConsume(TASK_QUEUE_NAME, autoAck, consumer);
When RabbitMQ quits or crashes it will forget the queues and messages unless you tell it not to. We need to mark both the queue and messages as durable.
boolean durable = true;
channel.queueDeclare("hello", durable, false, false, null);
Set the message to persistent
channel.basicPublish("", TASK_QUEUE_NAME,
MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
The persistence guarantees aren't strong, but it's more than enough for our simple task queue. If you need a stronger guarantee you can wrap the publishing code in a transaction.
Fair dispatch
In order to defeat that we can use the basicQos method with the prefetchCount = 1 setting. This tells RabbitMQ not to give more than one message to a worker at a time. Or, in other words, don't dispatch a new message to a worker until it has processed and acknowledged the previous one. Instead, it will dispatch it to the next worker that is not still busy.
int prefetchCount = 1;
channel.basicQos(prefetchCount);
Update the version to 3.3.1
>sudo ln -s /Users/carl/tool/rabbitmq_server-3.3.1 /opt/rabbitmq-3.3.1
>sudo ln -s /opt/rabbitmq-3.3.1 /opt/rabbitmq
Start the Server
>sudo sbin/rabbitmq-server
Check and Stop the Server
>sudo sbin/rabbitmqctl status
>sudo sbin/rabbitmqctl stop
2. Start the Cluster of RabbitMQ and Using HA-Proxy
http://flyingdutchman.iteye.com/blog/1912690
http://sillycat.iteye.com/blog/2037218
I already have the .erlang.cookie set up.
>chmod 777 ~/.erlang.cookie
>chmod 400 ~/.erlang.cookie
>sudo chown -R carl ~/.erlang.cookie
>sudo chgrp -R staff ~/.erlang.cookie
>enable rabbitmq_management
The following plugins have been enabled: mochiweb webmachine rabbitmq_web_dispatch amqp_client rabbitmq_management_agent rabbitmq_management Plugin configuration has changed. Restart RabbitMQ for changes to take effect.
Start the Nodes
>sudo RABBITMQ_NODE_PORT=5672 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15672}]" RABBITMQ_NODENAME=rabbit1 sbin/rabbitmq-server -detached
>sudo RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}]" RABBITMQ_NODENAME=rabbit2 sbin/rabbitmq-server -detached
Check status
>sbin/rabbitmqctl -n rabbit2 cluster_status
Cluster status of node rabbit2@sparkworker1 ... [{nodes,[{disc,[rabbit2@sparkworker1]}]}, {running_nodes,[rabbit2@sparkworker1]}, {cluster_name,<<"rabbit2@sparkworker1">>}, {partitions,[]}] ...done.
>sbin/rabbitmqctl -n rabbit1 cluster_status
Cluster status of node rabbit1@sparkworker1 ... [{nodes,[{disc,[rabbit1@sparkworker1]}]}, {running_nodes,[rabbit1@sparkworker1]}, {cluster_name,<<"rabbit1@sparkworker1">>}, {partitions,[]}] ...done.
We can visit the UI Admin Page
http://localhost:15672/#/
http://localhost:15673/#/
Default username and password is guest/guest
Stop and Make the Second Node join Cluster
>sudo sbin/rabbitmqctl -n rabbit2 stop_app
>sbin/rabbitmqctl -n rabbit2 join_cluster rabbit1@sparkworker1
>sudo sbin/rabbitmqctl -n rabbit2 start_app
>sbin/rabbitmqctl -n rabbit1 cluster_status
Cluster status of node rabbit1@sparkworker1 ... [{nodes,[{disc,[rabbit1@sparkworker1,rabbit2@sparkworker1]}]}, {running_nodes,[rabbit2@sparkworker1,rabbit1@sparkworker1]}, {cluster_name,<<"rabbit1@sparkworker1">>}, {partitions,[]}] ...done.
The should be running on 127.0.0.1:5672, 127.0.0.1:5673
I will be working on to put a ha-proxy in front of rabbitmq.
References:
RabbitMQ 1 ~ 9
http://sillycat.iteye.com/blog/1565771 Installation from sources on redhat
http://sillycat.iteye.com/blog/1567052 Installation on ubuntu and redhat
http://sillycat.iteye.com/blog/1575002 Installation on CentOS
http://sillycat.iteye.com/blog/1575314 Java Client - Work Queue
http://sillycat.iteye.com/blog/1575816 Java Client - Publish/Subscribe
http://sillycat.iteye.com/blog/1578635 Java Client - Routing
http://sillycat.iteye.com/blog/1579464 Java Client - Topics
http://sillycat.iteye.com/blog/1582971 Java Client - RPC
http://sillycat.iteye.com/blog/2037218 MAC with Scala and Cluster
http://www.rabbitmq.com/install-generic-unix.html
http://flyingdutchman.iteye.com/blog/1912690