Message Queue genres

What is the MQ
the Message Queue (MQ), message queuing middleware. Many people say: MQ to implement asynchronous reconciliation even application of separation by sending and receiving messages, this gives the intuition is --MQ is asynchronous, for decoupling, but this is only the effect rather than the MQ purpose. MQ communications real purpose is to shield the underlying complexity of the protocol, the application layer defines a set of simpler protocol. Communication between two modules of a distributed system is either HTTP, either develop their own TCP, but both protocols are in fact the original agreement. HTTP protocol is difficult to achieve both ends of the communication - module A can call B, B can also take the initiative to call A, if you want to do this at both ends to be back WebServer, and does not support long connection (HTTP 2.0 libraries simply can not be found to). TCP is even more original, and stick package, heartbeat, proprietary protocols, think about scalp numb. MQ have to do is build a simple "agreement" on top of these agreements - the producer / consumer model. MQ gives me the "agreement" is not a specific communication protocol, but a higher level of communication model. It defines two objects - the producer called to send data; called consumers to receive data, providing an SDK so that we can define their own producers and consumers realize the message communication while ignoring the underlying communication protocol

There's MQ Broker

The schools usually have a server as a Broker, all messages transit through it. Producers send messages to it the end of his task, Broker put the initiative to push the message to the consumer (or consumers take the initiative polling)

Heavy Topic

kafka, JMS (ActiveMQ) fall into this genre, producer and key data will be sent to the Broker, Broker decide after comparing key to which the consumer. This model is our most common, is our impression that most of MQ. In this mode, a topic often a larger concept, even a system, it may be only one topic, topic sense that queue, the producers send key is equivalent to saying: "hi, put the data into key queue "

As shown above, Broker defines three queues, key1, key2, key3, when the producer sends transmission data key1 and data, Broker when push push data is data (the key might take).

Although the same architecture but the performance kafka performance than high jms do not know how many times, so basically this type of MQ only kafka an alternative. If you need a data stream violence (and not care about performance flexibility) it is the best choice kafka

Light Topic

This is represented by RabbitMQ (or is AMQP). And key data sent by the producer, consumer subscription queue definitions, data is received after Broker calculated through a certain key corresponding to a logical queue, and the data to the queue

In this mode decoupling of the key and queue, the queue in this architecture is extremely lightweight (in RabbitMQ in its upper limit depends on your memory), consumers are concerned only with their own queue; producers do not care just specify to whom data is ultimately key on the line, the middle layer of mapping called exchange (switch) in the AMQP.

There are four exchange AMQP

Direct exchange: key is equivalent to queue
Fanout the Exchange: ignore key, to all of the queue to have a
Topic exchange: key can use the "wide character" fuzzy matching queue
Headers the Exchange: ignore key, be determined by looking at the message header metadata sent to the queue (AMQP head of metadata is very rich and can be customized)
architecture of this structure to the communication has brought a lot of flexibility, we can think of communication can be used to express these four exchange. If you need an enterprise data bus (care flexibility) so RabbitMQ absolutely worth a look

None of MQ Broker

No representative MQ Broker is ZeroMQ. The author is very wise, he was keenly aware of --MQ is more advanced Socket, it is to solve the communication problem. So ZeroMQ is designed as a "library" rather than a middleware, this implementation can also be achieved - there is no purpose Broker

Message communication between nodes is sent to another queue, each node is both a producer and consumer. ZeroMQ done is a set of packages may be similar to the Socket API finished sending data, the read data

ZeroMQ is actually a cross-language, heavyweight mailbox Actor model library. You can put your own program imagine a Actor, ZeroMQ is to provide library mailbox function; ZeroMQ can achieve the same machine RPC communication can achieve different machines TCP, UDP communications, if you need a powerful, flexible, savage ability to communicate, do not hesitate ZeroMQ

Attachment: the difference Queue and Topic

Queue: a publisher publishes a message, the receiver receives the following order according to the queue, such as a release message 10, two receivers A, B that A, B will receive a total of 10 messages, will not be repeated.
Topic: a publisher announced that there are two receivers A, B to subscribe to, then released 10 news, A, B each receive 10 messages.
Type Topic Queue
Summary Publish Subscribe Messaging publish-subscribe messaging Point-to-Point point
whether the state Topic default data does not fall, is stateless. Queue default data will be saved as a file on the MQ server, such as ActiveMQ typically stored in $ AMQ_HOME \ data \ kr-store \ data below. You may be configured to store DB.
Does not guarantee protection of the integrity of each data released by Publisher, Subscriber can receive. Queue ensure that each data can be received Receiver.
In general if the message will be lost when the Publisher publish a message to a Topic, only listening to the Topic address Sub able to receive the message; if there is no Sub listening, the Topic is lost. Sender sends a message to the target Queue, Receiver can receive messages asynchronously on this Queue. Message Queue on temporarily if there is no Receiver to take, is not lost.
Post a message received many of the policy released receive policy, monitor multiple addresses with a Topic Sub Publisher you can receive messages sent. Sub-one after receiving notification MQ server receives the policy news release, a message is sent by Sender, Receiver only one reception. Receiver is received, it has received notification MQ server, MQ server or take other actions to delete messages in the Queue.

Guess you like

Origin www.cnblogs.com/snake107/p/11920881.html