[Guide] combat RabbitMQ RabbitMQ study notes a Getting Started

1, messaging middleware

1.1 What is the message middleware

Middleware message (Message Queue Middleware, referred to as MQ) is the use of message passing efficient and reliable data exchange platform-independent, and for distributed system integration based on the data channel.

1.2, the role of messaging middleware

  • Decoupling: In the beginning of the project start to predict what the future will meet the needs of the project, is extremely difficult. The message queue processing is inserted in the middle of an implicit, based on the interface layer data, the processing to be implemented on both sides of the interface. This allows you to independently extend or modify the process on both sides, just make sure that they comply with the same interface constraints.
  • Redundancy (storage): Sometimes the process will fail when processing data. Unless the data is persisted, or they will be lost forever. Message Queue data for persistence until they have been fully processed, by this way to avoid the risk of data loss. Being used by many message queue "Insert - get - to delete" paradigm, before the message removed from the queue, you need a process clearly indicates that the message has been processed to ensure that your data is safe save until you are finished using.
  • Scalability: since the message middleware solution donated process applications, efficiency is improved and the enqueued message handling is easy, as long as the process can be further increased, without changing the code, do not need to adjust the parameters.
  • Traffic clipping: In the case of the sharp increase in traffic, applications need to continue to play a role, but this is not common burst traffic. If the peak to be able to deal with such standards and commit resources, it is undoubtedly a huge waste. Use messaging middleware component capable of supporting a burst access critical pressure, it will not be overloaded burst request collapse completely used.
  • Recoverability: when the portion of the system component failure, does not affect the entire system. Messaging middleware reduces the degree of inter-draft process, so even if a process of processing the message hang up, added messaging middleware messages can still be processed after the system recovery.
  • Order to ensure that: In most usage scenarios, the order data processing is very important, most messaging middleware to support the order of a certain degree.
  • Buffer: any significant system, there will need different processing time element. Messaging middleware through a buffer layer to help perform the task most efficiently, written messaging middleware processing will be as fast as possible. The buffer layer help to control and optimize the speed of data flow through the system.
  • Asynchronous communication: in many cases do not want to use does not need to process the message immediately. Messaging middleware provides asynchronous processing mechanism that allows applications to put some message into the messaging middleware, but does not deal with it immediately when needed and then slowly after treatment.

1.3, disadvantages messaging middleware

  • Reducing system availability: MQ added to the system, if linked to the MQ, Ben collapse of the entire system
  • Increase system complexity: the introduction of MQ will have some problems, such as how to ensure that the message is not repeated consumption, how to deal with situations such as lost messages

2, RabbitMQ Profile

RabbitMQ is the use of Erlang language AMQP (Advanced Message Queuing Protocol, Advanced Message Queuing Protocol) messaging middleware.

2.1, RabbitMQ Features

  • Reliability: RabbitMQ use some mechanism to ensure the reliability, such as persistence, transmission and distribution of confirmation confirmation
  • Flexible routing: Before entering the message queue, the message is routed through the switch. Typical routing function, RabbitMQ has provided some built-in switch to achieve. For more sophisticated routing capabilities, multiple switches can be bundled together, can also be achieved through their exchange plug-in mechanism
  • Scalability: RabbitMQ node comprises a plurality of clusters, the cluster may be extended node dynamically based on actual business situation
  • Plug-in mechanism: RabbitMQ provides a number of plug-ins to achieve extended in many ways, of course, you can also write your own plug-ins
  • High availability: queue may be provided in the mirror machines in the cluster, then such queues can be used in case of any problems portions node
  • Multiple protocols: RabbitMQ AMQP addition to native support for protocol also supports STOMP, MQTT other messaging middleware protocols
  • Multi-language client: RabbitMQ supports almost the common language used, such as Java, Python, Ruby, PHP, etc.
  • Management Interface: RabbitMQ provides an easy to use user interface, enabling users to monitor and manage messages, and other nodes in the cluster

2.2, related concepts

Is a producer-consumer model on RabbitMQ as a whole, is responsible for receiving, storing and forwarding messages. The process of message delivery can imagine: when a system you will be a package to the post office, the post office will be temporarily stored and eventually hands the message to the recipient by the postman, RabbitMQ is like a post office, mail and postman consisting of . The term level, from the computer, RabbitMQ model more like a switch model. RabbitMQ overall model architecture as shown:

 

  • Producer : the producer, it is one of the delivery of the message. 
  • Consumer : Consumer is the party that receives the message. 
  • Broker : messaging middleware service node. Figure shows producers messages into RabbitMQ Broker, Broker and consumer spending data from the entire process
  • Queue : Queue is RabbitMQ internal object, for storing messages.
  • The Exchange : switch. Producer will send a message to the Exchange, the switch routes the message to one or more queues. If the route is less than might be returned to the producer, and perhaps discarded. DETAILED shown a schematic view of the switch in FIG.
  • RoutingKey : routing keys. When the producers message to the switch, usually assigns a RoutingKey, it is used to specify the message routing rules, and this RoutingKey need to exchange types and key bindings (BindingKey) used in combination in order to ultimately take effect. 
  • The Binding : binding. RabbitMQ bound by the exchanger associated with the queue up at the specified time will generally bind a binding key (bindingKey), so RabbitMQ know how to route messages to the correct queue, as shown in

2.3 exchanger type

RabbitMQ common types exchanger fanout, direct, topic, headers four. 

  • fanout : it will all be sent to the message routing switch all bound to the switch queue. 
  • Direct : it will route the message to those BindingKey and RoutingKey exact match queue. 

     

  • Topic : Topic exchanger type matching rule performed on the extension, which is similar to the direct type switch, but it supports fuzzy matching, it has the following convention:
    • RoutingKey a dot "" separated strings, such as "com.rabbitmq.client", "java.util.concurrent", "com.hidden.client"
    • BindingKey RoutingKey and also as dot "" separated string; 
    • BindingKey can exist in two special string " " and "#" for doing fuzzy matching, which " " is used to match a word, "#" to match the multi-standard word (may be zero). 

            

 

 

    • Figure
      • Routing keys as "com.rabbitmq.client" message will also be routed to Queuel Queue2, and; 
      • Routing keys as "com.hidden.client" message will be routed to the Queue2:
      • Routing keys as "com.hidden.demo" message will be routed to the Queue2:
      • Routing keys as "java.rabbitmq.demo" message will be routed to Queuel in: 
      • Routing keys as "java.util.concurrent" message will be discarded or returned to the producer (mandatory parameter needs to be set), because it does not match any routing keys.
  • headers : the headers exchanger type matching rule does not depend on routing keys to route the message, but according to the match in the content transmission message headers property. Developing a set of key-value pairs when bound to the queue and switches, when the switch sends a message to the time, will be acquired RabbitMQ headers of the message (also in the form of a key-value pairs), wherein the comparison value pairs exactly matches specified queue and switches to bind key-value pairs, if exact match then the message will be routed to the queue, it will not be routed to the queue. type headers exchanger performance will be poor, and not practical, its presence does not substantially saw. 

Guess you like

Origin www.cnblogs.com/Zhangcsc/p/11655718.html
Recommended