What is a message queue? I think everyone knows it, so much so that it needs no explanation. However, any study or interpretation of something should follow the question “What is it?” “, “What is it for? “, “Why use it”, “what classification does it have”, so first still need to give a definition.

There is no definition in the world, so I have to give a definition: message queue, first is a queue, first in first out; Then, it passes the message…

1. Asynchronous processing will not be necessary for asynchronous processing of business logic, in other words, it can be returned immediately.

For example, after the registration information is written to the database, it needs to send an email or SMS notification. If you wait for both of these two steps to complete before returning, no matter whether the two steps are serial or parallel, it takes time. After the message queue is introduced, the registration information is written to the database, which is then written to the message queue, and can then be returned, with the message queue handling the rest of the work. This approach is even more advantageous if other operations, such as adding credits, are added in addition to sending notifications, and the business body does not have to change at all, just the message queue part.

2. Apply decoupling

Calls between two systems (or modules) that used to be direct are now indirect calls via message queues, like event triggers, which change the relationship between the two systems or modules from direct coupling to loose coupling.

3, flow peak cutting

This is a little bit easier to understand, so let’s introduce queuing. Turns concurrency into serial. If the message queue length exceeds the maximum number, the user request is discarded or the error page is redirected.

4, since the message communication is a message queue, how to send messages less?

5. Log processing

I think this belongs in the category of applying decoupling, why list it separately?

The following describes messaging services and their use in JMS. JMS is a Message service in Java and its API is a standard/specification for a message service.

Second, message model

P2P mode consists of three roles: Queue, Sender, and Receiver. Each message is sent to a specific queue from which the receiver retrieves the message. Queues hold messages until they are consumed or time out.

P2P features:

1) Each message has only one consumer, and once consumed, the message is no longer in the message queue.

2) There is no time dependence between the sender and the receiver, that is, when the sender sends a message, no matter whether the receiver is running or not, it will not affect the message being sent to the queue.

3) After receiving the message successfully, the receiver must reply to the queue successfully.

P2P is needed if you want every message sent to be processed successfully.

The producer/consumer (Pub/Sub) pattern consists of three role topics, Publisher and Subscriber. Multiple publishers send messages to Topic, and the system transmits these messages to multiple subscribers.

Pub/Sub features:

1) Each message can have multiple consumers

2) There is a temporal dependency between publisher and subscriber. For subscribers to a Topic, it must create a subscriber before it can consume the publisher’s messages

3) In order to consume messages, subscribers must remain running. Or create a persistent subscription. This way, the subscriber can receive the publisher’s message even if it is not activated (running).

The Pub/Sub model can be used if you want to send messages that can be processed without any processing, by a single message maker, or by multiple consumers.

Message consumption For consumption, there are two ways: 1. Synchronous subscribers or receivers block messages until they receive them

2. The asynchronous subscriber or receiver registers a message listener and reads the message when it arrives.

General commercial containers, such as WebLogic and JBoss, support the JMS standard and can directly use message queues. However, free ones such as Tomcat, Jetty, etc. require the use of third-party message-oriented middleware. The following is a common message-oriented middleware: 1. ActiveMQ Apache. Touted as the most popular and powerful open source message bus. Features are compatible with common J2EE server, support Spring, Ajax

RabbitMQ’s popular, open source message queue. Implemented with AMQP (Advanced Message Queue Protocol) standard. Supports multiple clients, including. Net, Java, PHP. Store and forward messages in distributed systems. Ease of use, scalability, high availability, etc.

3. ZeroMQ claims to be the fastest message queue in history and is actually a series of interfaces similar to sockets. Normal sockets have an end-to-end (1:1) relationship, whereas ZMQ is N:M. ZMQ shields the details of various connections, making network programming easier. Used for communication between nodes. A node can be a host or process.

Kafka high throughput distributed publish subscribe messaging system. Persistent high throughput cluster, partition support Hadoop

Resources: Link here to use message queues