A, MQ called the Message Queue, the message queue (MQ)
An application communication method to the application . Applications communicate via message (data for the application program) read out of the queue , without the need for a dedicated connection to link them.
Refers to message passing communication between a program in the data message transmitted by , rather than through direct calls to communicate with each other, is a technique commonly called directly, such as remote procedure calls.
It refers to the application queue by the queue to communicate . Removed using a queue and transmission requirements received concurrently executing applications.
二、AMQP 即 Advanced Message Queuing Protocol
Advanced Message Queuing Protocol , is an open standard application-layer protocol for message-oriented middleware design. Message middleware mainly for decoupling between the components , sender of the message without knowing the user's presence information, and vice versa.
AMQP main feature is a message for the queue, the routing (including point and publish / subscribe), reliability and safety .
Three, Rabbitmq concept:
Belonging to a popular open source system message queue. Belonging to the AMQP (Advanced Message Queuing Protocol) to achieve a standard. Is an open standard application-layer protocol is message-oriented middleware design . In a distributed system for store and forward messages , in terms of ease of use, scalability, high availability, and so doing well .
RabbitMQ Features:
Use written in Erlang
support persistence
support HA
provides C #, erlang, java, perl , python, ruby and other client-side development
Fourth, what is the coupling, decoupling
A coupling
1, the coupling means between two or more systems or affect the movement of both forms interact with each other as well as together by the phenomenon.
2, in software engineering , is the degree of coupling between objects dependencies between objects . Between objects higher coupling, higher maintenance costs , so the design should minimize the object class and the coupling between the member.
3, classification: there is coupling between the coupling, as well as hardware and software between the software modules . Coupling is a measure of the program structure of the linkages between the various modules . It depends on the complexity of the interface between each module, the calling module and what information the way through the interface.
Second, decoupling
1, decoupling, literally means to decouple the relationship.
2, in software engineering, to reduce the degree of coupling can be understood as decoupling i.e., there must exist dependencies between modules coupling , the coupling is zero theoretically absolutely impossible, but can be identified by conventional methods to reduce the degree of coupling to a minimum.
3, the design of the core idea: to minimize coupling of code , if the code is coupled found, it is necessary to take decoupling technology. Let data model, business logic and views between the three lower display coupled to one another, the association relies to a minimum, and thus will not affect the situation as a whole. A principle feature of the code is not written in the function code B, if needed interaction between the two, through the interface, through a message, or even the introduction of the framework, but in short, is not to write directly cross.
Five, RabbitMQ conceptual terms
Broker: is simply a message queue server entity . ?
Exchange: Message Switch , it specifies the message according to what rules, which are routed to a queue . ?
Queue: Message Queuing carrier , each message will be put into one or more queues. ? The Binding: binding, its role is to exchange routing and queue bind in accordance with the rules .
? Routing Key: routing keywords, exchange of messages delivered in accordance with this keyword .
? vhost: Web Hosting, a broker where you can set up multiple vhost, as a different user privilege separation .
producer: news producer, is the program delivered the message . ?
consumer: consumer news, is that the program accepts messages. ?
channel: message channels, in each client's connection can create multiple channel, each channel representing a conversation task?.
Six, RabbitMQ work management
MQ consumption - a model representative of typical producer, end to continue to write messages in the message queue, and the other end can be read or subscribe to messages in the queue. MQ is a concrete follow AMQP protocol implementations and products. In the project, some return immediately without time-consuming operations and extracted performs asynchronous processing and asynchronous processing in this manner greatly saving requests the server response time, thereby increasing the throughput of the system.
(1) Message Queuing clients connect to the server to open a channel. ?
(2) a declaration client exchange, and provision of the relevant property. ?
(3) The client declares a queue, and set the associated property. ?
(4) The client uses routing key, establish a good relationship between the exchange and the binding queue.
? (5) client posting messages to the exchange. ?
(. 6) Exchange After receiving the message, according to the message and key binding has been set, into? OK message routing, message delivered to one or more queue
Seven, Rabbitmq of metadata (metadata)
Metadata can be persistent in the RAM Disc or from this angle RabbitMQ can be divided into two nodes in a cluster. : RAM and the Node Disk Node.
RAM only the Node metadata stored in the RAM
Disk node metadata will be persisted to disk.
Single-node system is not any choice, allowing only disk node, or because there is no data redundancy, once restarted will lose all the configuration information, but in a clustered environment can choose which nodes are RAM node. Declare (declare) in the cluster Creating exchange queue binding, such operations until all nodes are finished creating will return:
If it is necessary to modify the memory node memory data,
if it is necessary to wait for the write to disk disk node, the node excessive speed here will be greatly the slow down.
Some scenes exchang queue fairly constant, change very little, and that even if all disc node, there is no effect if used Rabbitmq do RPC. (RPC: Remote Procedure Call- remote procedure call), RPC or RPC-like scene this serious problem the frequent destruction create a temporary queue, the disk reading and writing skills quickly become a performance bottleneck. Therefore, in most cases, we try to create a Node for the RAM Node. Here there is a problem, metadata in order to restart the cluster may need to restore the cluster metadata persisted to disk, it requires planning RabbitMQ cluster RAM Node and Disc Node.
As long as there is a node Disc Node will be able to provide the conditions for the cluster metadata written to the disk, RabbitMQ and indeed such requirements: a cluster as long as one disk node can, others can be a RAM node cluster nodes to join or withdraw from certain at least to notify a disk node in the cluster.
As if the cluster disk node are dawdle away, do not change the metadata of the cluster. Disclaimer exchange queue modify user permissions, add users, etc. These changes can not be recovered after a node restart.
A situation requires that all disk node to be the case in order to operate online that add or remove nodes .RAM node will start when connected to the predefined disk node to download the latest cluster metadata. If you have two disk node (d1 d2), when a RAM node join you just tell d1, and just this RAM node restart when d1 does not start, restart will fail. so when adding RAM nodes, all the disk node information to tell it will RAM node disk node information is persisted to disk for subsequent startup can find what you want.
Eight, Rabbitmq cluster deployment
192.168.253.135 bb 192.168.253.171 aa 192.168.253.153 cc
yum install -y erlang rabbitmq-server.noarch systemctl enable rabbitmq-server.service systemctl start rabbitmq-server.service systemctl status rabbitmq-server.service
rabbitmqctl change_password guest admin # change the password admin, and user name can not begin with numbers
node1: rabbitmqctl add_user Mama ADMIN rabbitmqctl set_permissions Mama " *. " " *. " " *. " rabbitmqctl set_user_tags Mama Administrator # Set the administrator can log in
RABBITMQ_NODE_PORT=5672 ulimit -S -n 4096 RABBITMQ_SERVER_ERL_ARGS="+K true +A30 +P 1048576 -kernel inet_default_connect_options [{nodelay,true},{raw,6,18,<<5000:64/native>>}] -kernel inet_default_listen_options [{raw,6,18,<<5000:64/native>>}]" RABBITMQ_NODE_IP_ADDRESS=192.168.253.135
scp /etc/rabbitmq/rabbitmq-env.conf aa:/etc/rabbitmq/
scp /etc/rabbitmq/rabbitmq-env.conf cc:/etc/rabbitmq/
/usr/lib/rabbitmq/bin/rabbitmq-plugins list
rabbitmq-plugins enable rabbitmq_management
scp / var /lib/rabbitmq/.erlang.cookie aa: / var / lib / rabbitmq / .erlang.cookie scp / var /lib/rabbitmq/.erlang.cookie cc: / var /lib/rabbitmq/.erlang.cookie
systemctl restart rabbitmq-server.service rabbitmqctl stop_app rabbitmqctl join_cluster --ram rabbit@bb rabbitmqctl start_app
rabbitmqctl stop_app
rabbitmqctl change_cluster_node_type disc (ram)
The Rabbit @ CC INTO A Turning the Node RAM ...
Error:. Mnesia IS ON Still running the Node The Rabbit @ CC
. Please STOP with the Node at The First # rabbitmqctl stop_app can see the need to stop the application
After stopping execution again
[root@cc rabbitmq]# rabbitmqctl change_cluster_node_type ram
Turning rabbit@cc into a ram node ...
rabbitmqctl start_app
stop_app rabbitmqctl
rabbitmqctl the RESET
---- "Resetting the Node The Rabbit @ cc ...
[root @ cc RabbitMQ] # rabbitmqctl cluster_status # view the status of discovery cc leaves the cluster node
Cluster Status of the Node The Rabbit @ cc ...
[{Nodes, [ disc {, [Rabbit @ CC]}]}, # departing from the cluster node will automatically become disc way, the reason below. 1
{running_nodes, [Rabbit @ CC]}, {CLUSTER_NAME, << "Rabbit @ CC" >>}, # and no other node names are not described within the cluster
{Partitions, []},
{Alarms, [{Rabbit @ CC, []}]}]
rabbitmqctl forget_cluster_node rabbit@node3
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status