RabbitMQ installation, cluster construction, coding

Source: Internet
Author: User
Tags alphanumeric characters rabbitmq

RabbitMQ

I. BACKGROUND


Command-line tools:
http://www.rabbitmq.com/man/rabbitmqctl.1.man.html

Introductory Introductory article:
http://blog.csdn.net/anzhsoft/article/details/19563091
The content is clear:http://www.diggerplus.org/archives/3110

Exchange, Queue
producer sends the message to exchange (with Route key), consumer declares the queue (with Bind key), and then depending on the type of exchange that is combined (fanout, Direct, topic, headers), which is routed to a different queue.
Fanout (Broadcast): Route key and bind key do not take effect, and all bind to Exchange queue will receive the same message. bind, the queue name must be different (if the same, two consumer, only one can receive the message)
Direct: The route key and bind key must be exactly equal before they are received (a queue can provide multiple bind keys to exchange, and as long as one satisfies, it receives the message; multiple queues can also use the same bind key, This will receive the same message)

Topic: Simple regular match for route key

RPC mode is also supported:


If the bind is not a queue on exchange, even if producer sends a persistent message, the consumer of the bind queue will not receive the previous message. So queue must be created first, and if you want to receive messages all the time, the queue must be persisted.

Q, err: = Ch. Queuedeclare (
"QueueName",//Name
True,//durable
False,//delete when usused
True,//Exclusive
False,//no-wait
Nil,//arguments
)

Similarly, if you want to be able to receive messages sent before producer before consumer, it is necessary to create the corresponding queue name in advance, bind the corresponding exchange


Second, engage, deploy, build a cluster


Refer to Cluster Deployment:
http://blog.csdn.net/jljf_hh/article/details/17381425

Before deployment, you have to understand the Erlang cookie thing.
RABBITMQ'sClusteris attached to Erlang.ClusterTo work, you must first build a cluster of Erlang. The nodes in Erlang's cluster are implemented by a magic cookie in the process, which is stored in$home/.erlang.cookie(like my root user installed in my Root/.erlang.cookie), the file is 400 permissions. So it is necessary to ensure that each node cookie is consistent, otherwise the nodes can not communicate.

Erlang Cookies
Erlang nodes use a cookie to determine whether they is allowed to communicate with each other-for both nodes to be able To communicate they must has the same cookie. The cookie is just a string of alphanumeric characters. It can be as a long or short as.
Erlang would automatically create a random cookie file when the RabbitMQ server starts up. The easiest-proceed is-to-allow one node-to-Create the file, and then copy it to all of the other nodes in the cluster .
On Unix systems, the cookie is typically located in LL/var/lib/rabbitmq/.erlang.cookie Or$home/.erlang.cookie.
On Windows, the locations is C:\Users\Current User\.erlang.cookie (%homedrive% +%homepath%\.erlang.cookie) orc:\documents and Settings\Current User\.erlang.cookie, and C:\Windows\.erlang.cookie for RabbitMQ Windows service. If Windows Service is used, the cookie should are placed in both places.
As an alternative, you can insert the option "-setcookieCookies"In the Erl call in the Rabbitmq-server andrabbitmqctl scripts.

Reference:http://www.tuicool.com/articles/YbYvIj


ubuntu above deployment:
Direct reference to the official website, a few orders to be fixed:
To use our APT repository:
1) Add the following line to Your/etc/apt/sources.list:
   Deb http://www.rabbitmq.com/debian/ testing main
(Please note that the word testing-in is refers to the state of our release of RabbitMQ, and not any particular Debian Distribution. You can use it with the Debian stable, testing or unstable, as well as with Ubuntu. We describe the release as "testing" to emphasise, that we release somewhat frequently.)
(optional) To avoid warnings on unsigned packages, add ourPublic KeyTo your Trusted key list using Apt-key (8):
2)wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
sudo apt-key add rabbitmq-signing-key-public.asc
3) Runapt-get update.
Install packages as usual; For instance,
sudo apt-get install rabbitmq-server

CentOS above deployment:
Install an Erlang installation environment:
Rpm-ihttp://mirror.bjtu.edu.cn/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

Yum Install Erlang
Install the RABBITMQ (RPM link can behttp://www.rabbitmq.com/install-rpm.htmlTo obtain)

RPM-IVH http://www.rabbitmq.com/releases/rabbitmq-server/v3.4.2/rabbitmq-server-3.4.2-1.noarch.rpm

Although the sum up is such a few lines, special to ponder for several hours.

Once the installation is complete, the cluster can be organized.


Start:/sbin/service rabbitmq-server start
The Admin interface plugin can be opened by command: Rabbitmq-plugins enable Rabbitmq_management

Then: http://IP:15672/into the admin interface to view RABBITMQ information.

Start building the cluster:
1. Add user

Create a user on both machines and set up as an administrator, otherwise you will not be able to log in through the admin interface.

Rabbitmqctl add_user Sky Password
Rabbitmqctl set_user_tags Sky Administrator


2. Synchronizing Erlang cookie Data
If the Erlang cookie file is modified, the process and RABBITMQ of Erlang have been started and they are either stop or kill. Restart the Erlang cookie after changing it

The path to the Erlang cookie says, "ensure that the content is consistent."


3. Configure hosts to configure the host name and IP of each node in the hosts so that they can communicate with each other
the hostname here is [email protected] in the format of the text after the @, for example, here is: 10.12.13.54 Olymtech

4. Start two nodes respectively
Rabbitmq-server-detached


5. On the slave node, join to the master node,
host2# Rabbitmqctl Stop_app
host2# rabbitmqctl join_cluster [email protected] PS: Here Olymtech does not need to do this, is to let the olymtech outside of the cluster in his name to join To
host2# rabbitmqctl Start_app If you join and start successfully, you can see the node information on the management interface (here Two nodes are persisted type, if necessary can be added in the join_cluster-ram option, configured as memory node):

Here if the start or stop failed, PS Rabbit process, press all kill off, and then again.


6. Add a policy
Rabbitmqctl set_policy Ha-all "^ha\." ' {' Ha-mode ': ' All '} '
Generally ha. The data for the start queue will be synchronized to all node of the cluster
OK, so it's set up, and then you can write code.

Here, if you want to do the load, HA, you need to put a set of TCP proxy, responsible for monitoring and forwarding, for example: HAProxy, lvs+keepalive. I haven't done it yet.


Program connection times wrong:
2014/12/16 11:44:31 emit_log.go:14:failed to connect to Rabbitmq:exception (403) Reason: ' No access to this ghost '

Because the user's access rights are not configured, you can
Rabbitmqctl Add_vhost Skytest
To add, and give permissions:
Rabbitmqctl set_permissions-p Sky skytest ". *" ". *" ". *"
Similarly, when the code is connected, the corresponding vhost must be set up, otherwise there is no access permission to drop:
Conn, err: = Amqp. Dial ("Amqp://sky:[email protected]:5672/skytest")

For the Go Language library, refer to:

Https://godoc.org/github.com/streadway/amqp

RabbitMQ installation, cluster construction, coding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.