Rocket MQ and WebSocket integrated high-performance real-time communication system and method
By combining the modular design of RocketMQ and WebSocket, the challenges of high-concurrency and high-reliability real-time communication are solved, efficient front-end and back-end communication is achieved, the reliable delivery and sequentiality of messages are ensured, and dynamic expansion and load balancing of the system under high load are supported.
Patent Information
- Application Number
- CN202510028749.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-08
- Publication Date
- 2025-10-03
AI Technical Summary
How to achieve seamless integration of RocketMQ message queue and WebSocket protocol to solve the problems of high concurrency, high reliability and real-time communication.
By combining the RocketMQ message queue module, WebSocket service module, message routing and filtering module, message confirmation and receipt mechanism, dynamic expansion and load balancing module, and message delayed sending module, efficient front-end and back-end communication is achieved.
It achieves high concurrency, high reliability and real-time communication between the front-end and back-end, ensures the reliable delivery and sequence of messages, and supports dynamic expansion and load balancing of the system under high load conditions.
Smart Images

Figure CN120743571A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more particularly to front-end communication functionality based on RocketMQ and WebSocket. By combining RocketMQ message queues with the WebSocket protocol, this technology aims to provide an efficient, reliable, and real-time front-end and back-end communication solution. It is widely applicable to application scenarios requiring high concurrency, high reliability, and real-time data delivery. Background Art
[0002] With the increasing complexity of internet applications and user demands, the traditional HTTP-based request / response model can no longer meet the real-time and high-concurrency requirements of modern systems. Real-time communication technology is particularly important in applications that require instant data push and notifications, such as e-commerce platforms, social media, and industrial services.
[0003] As a full-duplex, real-time communication protocol, WebSockets is widely used for instant data exchange between front-end and back-end servers. However, relying solely on WebSockets for communication presents challenges in high-concurrency and high-reliability scenarios, particularly in areas such as message queue management, message ordering, and load balancing.
[0004] RocketMQ is a high-performance, distributed message queue system widely used for message delivery and distribution in highly concurrent, distributed systems. It effectively guarantees message reliability, sequentiality, and high throughput. However, since it does not directly support the real-time communication requirements of WebSocket clients, integrating the two is a major challenge.
[0005] Therefore, how to achieve seamless integration of RocketMQ message queue and WebSocket protocol to realize efficient front-end and back-end communication has become a problem that needs to be solved urgently in current technology. Summary of the Invention
[0006] This invention provides a front-end communication function based on RocketMQ and WebSocket, which solves the problems of high concurrency, high reliability and real-time communication by combining the advantages of both. The technical solution of this invention includes the following main modules:
[0007] 1. RocketMQ message queue module: Utilizes the high concurrency, high reliability, and high throughput of RocketMQ message queue to store, deliver, and distribute messages, ensuring reliable delivery and sequentiality of messages.
[0008] 2. WebSocket service module: This module is used to establish a WebSocket connection with the front-end client, consume messages from the RocketMQ message queue, and push messages to the corresponding WebSocket client in real time.
[0009] 3. Message routing and filtering module: Based on the subscription information of the front-end client, selectively push messages to relevant clients to ensure that only relevant messages are pushed to the front-end that subscribes to the message.
[0010] 4. Message confirmation and receipt mechanism: The message confirmation mechanism ensures that the message is confirmed after being successfully received by the front-end client. If not confirmed, the back-end resends the message through RocketMQ to ensure the reliability of the message.
[0011] 5. Dynamic expansion and load balancing module: supports the system to dynamically expand WebSocket service instances and RocketMQ consumers under high concurrency conditions, ensuring efficient operation and load balancing of the system.
[0012] 6. Message delayed sending module: supports scheduled delayed sending of MQ messages, and records message details and consumption status in delayed message management to ensure that messages are sent on time and consumed successfully. DETAILED DESCRIPTION
[0013] The specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0014] The system of the present invention is mainly composed of the following parts:
[0015] Front-end client: Uses a browser or application that supports the WebSocket protocol to establish a persistent connection with the WebSocket server to send and receive real-time data.
[0016] WebSocket server: As a bridge for communication between the front-end and the back-end, it is responsible for receiving messages sent by the front-end, sending the messages to RocketMQ after processing, and pushing the messages processed by RocketMQ back to the front-end.
[0017] RocketMQ message queue: responsible for efficient management and distribution of messages, supporting message persistence, retry and partition processing, ensuring reliable message transmission and high concurrent processing capabilities. Backend application service: as the message consumer of RocketMQ, it processes received messages, executes corresponding business logic, and
[0018] The processing results are returned to the WebSocket server through the message queue.
[0019] The workflow of the present invention is as follows:
[0020] Establishing a connection: The front-end client establishes a persistent two-way communication connection with the WebSocket server through the WebSocket protocol.
[0021] Message sending: The front-end client sends real-time data messages to the WebSocket server. The WebSocket server receives the messages and sends them to the specified message topic as a RocketMQ producer.
[0022] Message processing: RocketMQ distributes messages to corresponding message consumption groups based on pre-set partitioning strategies. Backend application services act as consumers, subscribing to and receiving messages and executing specific business logic.
[0023] Message feedback: After processing is completed, the result message is sent back to RocketMQ, and RocketMQ pushes the message to the WebSocket server.
[0024] Message push: The WebSocket server receives the result message from RocketMQ and pushes the result back to the front-end client in real time through the previously established WebSocket connection.
[0025] Example: Industrial Platform Business Push
[0026] In an industrial platform, the backend uses RocketMQ message queues to store and distribute different business modules (such as Figure 1 When a business module needs to send a message, the system will send the message to the RocketMQ message queue, consume the message, and push it to the relevant client in real time (such as Figure 3 After receiving the message from RocketMQ, the WebSocket service module pushes it to the user who subscribed to the message via WebSocket (as shown in Figure 4 After the client successfully receives the message, it sends a confirmation receipt to the backend, and the backend confirms through RocketMQ that the message has been successfully consumed and processed.
[0027] When RocketMQ sends a timed delayed message, it records the delayed message details and consumption status separately (such as Figure 2 shown) BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 This is a diagram illustrating the RocketMQ message configuration.
[0029] Figure 2 This is a diagram illustrating the configuration of RocketMQ delayed messages.
[0030] Figure 3This is a diagram illustrating the RocketMQ message queue.
[0031] Figure 4 This is a diagram illustrating WebSocket.
Claims
1. A method for front-end communication based on RocketMQ and WebSocket, characterized in that: The process includes the following steps: the backend sends a message to the message queue through RocketMQ; the WebSocket service module establishes a WebSocket connection with the front-end client and obtains messages from the RocketMQ message queue; based on the message type subscribed by the front-end, the message is pushed to the corresponding WebSocket client; after receiving the message, the WebSocket client sends a confirmation receipt to the backend, and the backend records the consumption status of the message. The method according to claim 1, wherein The message queue supports high-concurrency message storage and distribution, and ensures the reliability and sequentiality of messages. The method according to claim 1, wherein The message routing and filtering module selectively pushes messages to specific WebSocket clients based on the front-end subscription information to ensure accurate message delivery. The method according to claim 1, wherein The system supports dynamic addition of WebSocket service instances to cope with high concurrent loads and can automatically scale according to load conditions. The method according to claim 1, wherein The message confirmation mechanism includes the front-end client sending a confirmation receipt after receiving the message, and the back-end recording the consumption status of the message through RocketMQ and re-pushing the message if it is not confirmed. A front-end communication system based on RocketMQ and WebSocket, characterized in that: include: A RocketMQ message queue module for storing and distributing messages; a WebSocket service module for establishing a WebSocket connection with the front-end client and pushing messages from the message queue to the front-end; a message routing and filtering module for selectively pushing messages to the corresponding WebSocket client based on the front-end subscription information; a message confirmation module for receiving confirmation receipts from the front-end client and updating the consumption status of the message; a message delayed sending module for RocketMQ timed delayed sending. The system according to claim 6, wherein The message queue module is implemented through RocketMQ, which supports the storage, distribution and reliable transmission of high-concurrency messages. The system according to claim 6, wherein The WebSocket service module supports dynamic expansion and can automatically increase WebSocket service instances according to system load. The system according to claim 6, wherein After receiving the confirmation receipt, the message confirmation module marks the message as successfully consumed. If no receipt is received, the message is pushed again through the message queue. The system according to claim 6, wherein The message routing and filtering module can filter messages according to message content or user subscription information, and only push messages to relevant front-end clients. The system according to claim 6, wherein The system also includes a load balancing module for balancing the load of message queue consumers and WebSocket service instances in high concurrency situations to ensure efficient operation of the system. The system according to claim 6, wherein The message is sent with a delay, and there is a delayed message management to record the consumption status.