Message Queue: A Distributed System for Efficient Messaging
Introduction
In today’s fast-paced digital landscape, applications require efficient and reliable messaging systems to handle a high volume of requests and transactions. A message queue is a distributed system that solves the problems of application coupling, asynchronous messaging, and traffic congestion. It provides a high-performance, high-availability, and scalable architecture with eventual consistency. In this article, we will explore the different scenarios where message queues are commonly used and examine the exemplary messaging middleware.
Message Queue Scenarios
Message queues are used in various practical application scenarios, including:
- Asynchronous Processing: After user registration, sending registered mail and SMS registration can be done asynchronously to improve performance.
- Application of Decoupling: Decoupling order processing from inventory management can be achieved using a message queue to improve system reliability and scalability.
- Flow Cut Front: Message queues can be used to control traffic and prevent application hang during spike activities.
- Log Processing: Message queues can be used to process logs, such as Kafka applications, to solve log transfer problems.
Asynchronous Processing
Scene Description: After user registration, sending registered mail and SMS registration can be done asynchronously to improve performance.
Traditional Practice: The conventional practice has two serial fashion; after the successful registration information into the database, send registered mail and then send the registration SMS.
Parallel Processing: After successful registration information into the database, and send a registered mail, send a registration SMS. The difference is that serial, parallel way of processing time can be improved.
Assumptions:
- Each service node is assumed that the use of three 50 msec clock, without considering other network overhead and the like.
- The time is 150 milliseconds in a serial fashion, and parallel time may be 100 milliseconds.
- The amount of the serial mode request can be processed within one second CPU is 7 times (1000/150).
- The amount of parallel processing is 10 (1000/100).
Summary: The performance of the traditional way of the system (amount of concurrency, throughput, response time) will be a bottleneck. Introducing the message queue, the service logic will not necessarily, asynchronous processing.
Application of Decoupling
Scene Description: After the user orders, the order system needs to notify the inventory system.
Traditional Approach: The traditional approach is that the interface inventory system order system call.
Message Queue Approach: After the introduction of the application program message queue, the order system writes messages to the message queue and returns the user orders a single Successful. The inventory system single subscription to the message, using the pull / push manner, acquires the order information, inventory information system according to the orders, inventory operation.
Flow Cut Front
Flow front is cut in the message queue common scenarios is generally used widely in the group or spike activity grab. To solve this problem, the general need to add the message queue in front-end applications. The number of possible control activities can ease the traffic overwhelmed by applications.
Log Processing
Log processing means in the message queue with log processing, such as Kafka applications, a number of problems to solve log transfer.
Message Communications
Message queues are generally built efficient communication mechanism, and therefore may be used in a pure message communication. Such as point to point message queue, or chat room.
Exemplary Messaging Middleware
Message queues are highly available persistent messaging middleware. For example, Active MQ, Rabbit MQ, Rocket Mq.
Electricity Supplier System
Message queues are highly available persistent messaging middleware. For example, Active MQ, Rabbit MQ, Rocket Mq.
Scene Description: After the user orders, the order system needs to notify the inventory system.
Traditional Approach: The traditional approach is that the interface inventory system order system call.
Message Queue Approach: After the introduction of the application program message queue, the order system writes messages to the message queue and returns the user orders a single Successful. The inventory system single subscription to the message, using the pull / push manner, acquires the order information, inventory information system according to the orders, inventory operation.
Log Collection System
Zookeeper divided registry, log collection client, a cluster of four parts Kafka and Storm cluster (OtherApp). Zookeeper registry proposed load balancing and address lookup services.
JMS Message Service
Speak the message queue have to mention JMS. JMS (Java Message Service, Java Message Service) API is a standard messaging service / specification that allows application components based on JavaEE platform to create, send, receive and read messages.
Message Model
In the JMS specification, there are two message model P2P (Point to Point), Publish / Subscribe (Pub / Sub).
P2P Mode
P2P mode comprising three roles: a message queue (Queue), a sender (Sender), receivers (Receiver). Each message is sent to a particular queue, the receiver acquires the message from the queue.
Pub / Sub Mode
Contains three roles topics (Topic), Publisher (Publisher), subscribers (Subscriber) more publishers send a message to Topic, the system will deliver these messages to multiple subscribers.
Consumer News
Produce and consume messages are asynchronous. For the consumer it is, JMS messages may be consuming messages in two ways.
JMS Programming Model
ConnectionFactoryCreate a Connection object factory jms messages for two different models, there are two separate QueueConnectionFactory and TopicConnectionFactory. Destination means of sending messages in the message producer or message target consumer sources. Connection indicates a link between the client and the JMS system established. Session messages is interface operation. Producer (5) of the message A message producer created by the Session, and for sending a message to the Destination. The message consumer Created by the message consumer Session, for receiving messages sent to the Destination.
Five Common Message Queue
General commercial vessels, such as WebLogic, JBoss, JMS supports standard, easy on development. But free such as Tomcat, Jetty and so you need to use a third-party messaging middleware. This section describes the common messaging middleware (Active MQ, Rabbit MQ, Zero MQ, Kafka) and their characteristics.
Apache ActiveMQ
Apache ActiveMQ is produced, most popular, strong ability to open source message bus. ActiveMQ is a fully supported JMS1.1 and J2EE 1.4 specification JMS Provider realize.