CN112769671A - Message processing method, device and system - Google Patents
Message processing method, device and system Download PDFInfo
- Publication number
- CN112769671A CN112769671A CN201910998278.5A CN201910998278A CN112769671A CN 112769671 A CN112769671 A CN 112769671A CN 201910998278 A CN201910998278 A CN 201910998278A CN 112769671 A CN112769671 A CN 112769671A
- Authority
- CN
- China
- Prior art keywords
- message
- server
- client
- websocket
- request
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000003672 processing method Methods 0.000 title claims abstract description 16
- 238000000034 method Methods 0.000 claims abstract description 45
- 238000012545 processing Methods 0.000 claims abstract description 25
- 238000004590 computer program Methods 0.000 claims description 19
- 238000004891 communication Methods 0.000 abstract description 4
- 238000010586 diagram Methods 0.000 description 10
- 238000011161 development Methods 0.000 description 4
- 230000000694 effects Effects 0.000 description 4
- 230000006870 function Effects 0.000 description 4
- 230000000903 blocking effect Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 3
- 230000005540 biological transmission Effects 0.000 description 2
- 238000012546 transfer Methods 0.000 description 2
- 238000010276 construction Methods 0.000 description 1
- 235000014510 cooky Nutrition 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L51/00—User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
- H04L51/21—Monitoring or handling of messages
- H04L51/214—Monitoring or handling of messages using selective forwarding
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/104—Peer-to-peer [P2P] networks
- H04L67/1044—Group management mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/55—Push-based network services
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/56—Provisioning of proxy services
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/161—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
- H04L69/162—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Mathematical Physics (AREA)
- Theoretical Computer Science (AREA)
- Computer And Data Communications (AREA)
Abstract
The invention provides a message processing method, a device and a system, relates to the technical field of communication, and aims to improve the speed of searching a WebSocket server executing a message pushing task, wherein the method comprises the following steps: the method comprises the steps that a proxy server receives a message pushing request for requesting to push a message to a first client, and then broadcasts a broadcast message carrying the message pushing request to a server cluster; and when the WebSocket server in the server cluster determines that the connection information of the first client is stored according to the message pushing request carried in the broadcast message, the WebSocket server pushes the WebSocket message corresponding to the message pushing request to the first client. The technical scheme provided by the invention is used for processing the WebSocket message.
Description
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method, an apparatus, and a system for processing a message.
Background
With the development of the internet, it is difficult for a conventional HyperText Transfer Protocol (HTTP) to meet the increasingly complex requirements of Web page (Web) applications. In recent years, with the advent of hypertext Markup Language (HTML) 5.0, a web port (WebSocket) protocol has been proposed, which can implement full duplex communication between a browser and a server, extend the communication function between the browser and a server, and enable the server to actively push data to a client, and thus has been widely applied to various fields.
Due to the fact that the bearing capacity of a single Websocket server is limited, when the number of clients is large, the single Websocket server can hardly support pushing tasks. Therefore, in order to serve more clients, more and more message push systems expand the push capability of the system by deploying a server cluster, wherein the server cluster is composed of a plurality of WebSocket servers, and message transmission can be performed between a client and the server cluster through a proxy server. When the existing message pushing system realizes message pushing, the connection relationship between the client and the server is generally stored through the shared storage system, and when a message pushing task exists, the WebSocket server executing the message pushing task is found by inquiring the connection relationship stored in the shared storage system, and then the server is informed to push the message.
However, in the above manner of searching for the WebSocket server executing the message pushing task through the shared storage system, the searching speed is slow.
Disclosure of Invention
In view of this, the present invention provides a message processing method, device and system, which are used to improve the speed of searching for a WebSocket server executing a message push task.
In order to achieve the above object, in a first aspect, an embodiment of the present invention provides a message processing method applied to a proxy server, including:
receiving a message pushing request for requesting to push a message to a first client;
and broadcasting a broadcast message carrying the message pushing request to a server cluster, wherein the broadcast message is used for indicating a web port WebSocket server in the server cluster to push a WebSocket message corresponding to the message pushing request to the first client when determining that the connection information of the first client is stored according to the message pushing request carried in the broadcast message.
As an optional implementation manner in this embodiment of the present invention, the broadcasting a broadcast message carrying the message push request to a server cluster includes:
and instructing the execution server to notify the message middleware to broadcast the broadcast message carrying the message pushing request to the server cluster.
As an optional implementation manner of the embodiment of the present invention, the message middleware is a Redis information distribution end.
As an optional implementation manner of the embodiment of the present invention, the method further includes:
when a connection request initiated by a second client is received, acquiring a server list from a registration center, wherein the registration center comprises registration information of a WebSocket server in an online state in the server cluster, and the server list is formed according to the registration information;
determining a target server according to the server list;
and forwarding the connection request to a target server to indicate the target server to establish connection with the second client according to the connection request.
As an optional implementation manner of the embodiment of the present invention, the registry is an Eureka registry.
As an optional implementation manner of the embodiment of the present invention, the WebSocket server is a node.
In a second aspect, an embodiment of the present invention provides a message processing method, which is applied to a WebSocket server in a server cluster, and includes:
receiving a broadcast message, wherein the broadcast message carries a message pushing request for requesting to push a message to a first client;
and when the connection information of the first client is determined to be stored according to the message pushing request, pushing the WebSocket message corresponding to the message pushing request to the first client.
As an optional implementation manner of the embodiment of the present invention, the message push request carries identity information of the first client, and when it is determined that connection information of the first client is stored according to the message push request, pushing a WebSocket message corresponding to the message push request to the first client includes:
and when the connection information of the first client is determined to be stored according to the identity information of the first client, pushing the WebSocket information corresponding to the message pushing request to the first client.
As an optional implementation manner of the embodiment of the present invention, the receiving a broadcast message includes:
receiving a broadcast message broadcast by message middleware.
As an optional implementation manner of the embodiment of the present invention, the method further includes:
registering with a registry at startup.
As an optional implementation manner of the embodiment of the present invention, the method further includes:
receiving a connection request forwarded by a proxy server, wherein the connection request is initiated by a second client;
and establishing connection with the second client according to the connection request, and storing the connection information of the second client.
As an optional implementation manner of the embodiment of the present invention, the method further includes:
and when the connection with the second client is disconnected, deleting the connection information of the second client.
As an optional implementation manner of the embodiment of the present invention, the WebSocket server is a node.
In a third aspect, an embodiment of the present invention provides a message processing apparatus, applied to a proxy server, including:
the receiving module is used for receiving a message pushing request for requesting to push a message to a first client;
and the processing module is used for broadcasting a broadcast message carrying the message pushing request to a server cluster, and the broadcast message is used for indicating a web port WebSocket server in the server cluster to push a WebSocket message corresponding to the message pushing request to the first client when determining that the connection information of the first client is stored according to the message pushing request carried in the broadcast message.
As an optional implementation manner of the embodiment of the present invention, the processing module is specifically configured to:
and instructing the execution server to notify the message middleware to broadcast the broadcast message carrying the message pushing request to the server cluster.
As an optional implementation manner of the embodiment of the present invention, the message middleware is a Redis information distribution end.
As an optional implementation manner of the embodiment of the present invention, the apparatus further includes:
the acquisition module is used for acquiring a server list from a registration center when the receiving module receives a connection request initiated by a second client, wherein the registration center comprises registration information of a WebSocket server in an online state in the server cluster, and the server list is formed according to the registration information;
the determining module is used for determining a target server according to the server list;
and the sending module is used for forwarding the connection request to the target server so as to indicate the target server to establish connection with the second client according to the connection request.
As an optional implementation manner of the embodiment of the present invention, the registry is an Eureka registry.
As an optional implementation manner of the embodiment of the present invention, the WebSocket server is a node.
In a fourth aspect, an embodiment of the present invention provides a message processing apparatus, which is applied to a WebSocket server in a server cluster, and includes:
the system comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving a broadcast message, and the broadcast message carries a message pushing request for requesting to push a message to a first client;
and the pushing module is used for pushing the WebSocket message corresponding to the message pushing request to the first client when the connection information of the first client is determined to be stored according to the message pushing request.
As an optional implementation manner in this embodiment of the present invention, the message push request carries identity information of the first client, and the push module is specifically configured to:
and when the connection information of the first client is determined to be stored according to the identity information of the first client, pushing the WebSocket information corresponding to the message pushing request to the first client.
As an optional implementation manner of the embodiment of the present invention, the receiving module is specifically configured to:
receiving a broadcast message broadcast by message middleware.
As an optional implementation manner of the embodiment of the present invention, the apparatus further includes:
and the registration module is used for registering with the registration center when starting.
As an optional implementation manner of the embodiment of the present invention, the receiving module is further configured to: receiving a connection request forwarded by a proxy server, wherein the connection request is initiated by a second client;
the device further comprises: and the connection module is used for establishing connection with the second client according to the connection request and storing the connection information of the second client.
As an optional implementation manner of the embodiment of the present invention, the apparatus further includes:
and the deleting module is used for deleting the connection information of the second client when the connection between the deleting module and the second client is disconnected.
As an optional implementation manner of the embodiment of the present invention, the WebSocket server is a node.
In a fifth aspect, an embodiment of the present invention provides a proxy server, including: a memory for storing a computer program and a processor; the processor is configured to perform the method of the first aspect or any of the embodiments of the first aspect when the computer program is invoked.
In a sixth aspect, an embodiment of the present invention provides a WebSocket server, including: a memory for storing a computer program and a processor; the processor is configured to perform the method of the second aspect or any of the embodiments of the second aspect when the computer program is invoked.
In a seventh aspect, an embodiment of the present invention provides a message processing system, including: the WebSocket server comprises a client, a server cluster and the proxy server in the fifth aspect, wherein the server cluster comprises a plurality of WebSocket servers in the sixth aspect.
As an optional implementation manner of the embodiment of the present invention, the system further includes: the execution server is used for notifying the message middleware to broadcast the broadcast message carrying the message pushing request to the server cluster according to the indication of the proxy server.
As an optional implementation manner of the embodiment of the present invention, the system further includes: the registry is used for providing a server list for the proxy server, wherein the registry comprises registration information of the WebSocket server in an online state in the server cluster, and the server list is formed according to the registration information.
In an eighth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method described in the first aspect, the second aspect, any implementation manner of the first aspect, or any implementation manner of the second aspect.
According to the message processing method, device and system provided by the embodiment of the invention, when the proxy server receives the message push request for requesting to push the message to the first client, the broadcast message carrying the message push request is broadcasted to the server cluster, so that the WebSocket server in the server cluster pushes the WebSocket message corresponding to the message push request to the first client when determining that the connection information of the first client is stored according to the message push request carried in the broadcast message.
Drawings
Fig. 1 is a schematic structural diagram of a message pushing system according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a message processing method according to an embodiment of the present invention;
fig. 3 is a schematic flowchart of another message processing method according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a message processing apparatus according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of another message processing apparatus according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a proxy server according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a WebSocket server according to an embodiment of the present invention.
Detailed Description
The embodiments of the present invention provide a message processing method, an apparatus, and a system, which mainly broadcast a broadcast message carrying a message push request to a server cluster when receiving a message push request requesting to push a message to a first client, so that a WebSocket server in the server cluster pushes a WebSocket message corresponding to the message push request to the first client when determining that connection information of the first client is stored according to the message push request carried in the broadcast message, thereby increasing the speed of searching for the WebSocket server executing the message push task.
The technical solution of the present invention will be described in detail below with specific examples. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments.
Fig. 1 is a schematic structural diagram of a message pushing system according to an embodiment of the present invention, and as shown in fig. 1, the message pushing system according to the embodiment may include: a client 100, a proxy server 200 and a server cluster 300, wherein the server cluster 300 may include a plurality of WebSocket servers 301.
In this embodiment, the client 100 may be an electronic device with display, operation and network access functions, for example, a mobile device such as a mobile phone, a tablet computer, a notebook computer or an intelligent wearable device, or a fixed device such as a desktop computer or a television with a network access function. The number of the clients 100 may be multiple, and a user may establish a connection with the WebSocket server 301 in the server cluster 300 through a browser on the client 100. It should be noted that, the connections between the client 100 and the WebSocket server 301 in the embodiment of the present invention are all connections based on the WebSocket protocol.
The WebSocket server 301 in the server cluster 300 may specifically be a server developed based on blocking input/output, such as a Tomcat server; to improve the system load-bearing capacity, the WebSocket server 301 may also be a server developed based on non-blocking input/output, such as: a Netty server and a node.js server, wherein the node.js server is lightweight and efficient, and the server construction method is simple, and therefore, the node.js server is preferably used in this embodiment.
The proxy server 200 is configured to perform message transfer between the client 100 and the server cluster 300, and may receive a message sent by the client 100 to the server cluster 300, and forward the message to the corresponding WebSocket server 301; or may receive a message sent by the WebSocket server 301 to the client 100, and forward the message to the corresponding client 100. The proxy server 200 may be a server that is responsible for the equalization, such as ngache or F5, and the proxy server 200 in this embodiment preferably uses the nganx, because the nganx configuration is simple, the performance is high, and the cost is low.
In this embodiment, when receiving a message push request for requesting to push a message to a certain client 100 (referred to as a first client 100 herein), the proxy server 200 may broadcast the message push request to the server cluster 300 in a broadcast manner, and after receiving the broadcast message push request, the WebSocket server 301 in the server cluster 300 may query whether the WebSocket server itself stores the connection information of the first client 100, and if so, push the WebSocket message corresponding to the message push request to the first client 100 (for a specific description, see the following method embodiments). Compared with the mode of inquiring the WebSocket server 301 executing the message pushing request (namely the message pushing task) in the record containing all the client-side 100 connections, the searching speed can be effectively increased, and the record containing all the client-side 100 connections does not need to be established.
In broadcasting the message push request, in this embodiment, the proxy server 200 may specifically send the message push request to the execution server 400, and instruct the execution server 400 to notify the message middleware 500 to broadcast the message push request to the server cluster 300. That is, in this embodiment, the message pushing system may further include: the execution server 400 and the message middleware 500.
The execution server 400 is used to execute the operation of the access message middleware 500 allocated by the proxy server 200, and may be a server developed based on blocking input/output, such as a Tomcat server, which has a low development cost and can reduce the system cost as the execution server 400; the execution server 400 may be another server having a function of accessing the message middleware 500, and this embodiment is not particularly limited thereto.
The message middleware 500 may implement broadcasting of a message, which may specifically be a Redis information publishing end, and may also be an information publishing end such as Kafka or rabitmq, where the processing speed of the Redis information publishing end is fast, and the speed of searching for the WebSocket server 301 executing the message push task may be increased by using the Redis information publishing end as the message middleware 500. WebSocket server 301 in server cluster 300 may subscribe to message middleware 500 and receive messages broadcast by message middleware 500.
In order to facilitate the proxy server 200 to distribute the connection request, in this embodiment, the message pushing system may further include: a registry 600. When the WebSocket server 301 in the server cluster 300 starts, it may register with the registry 600; the registry 600 may determine the online WebSocket server 301 list according to the registration information of the WebSocket server 301 started (i.e., in an online state) in the server cluster 300. When a new client 100 (referred to as a second client 100) initiates a connection request, the proxy server 200 may obtain a list of servers available for invocation from the registry 600, determine a server (referred to as a target server herein) from the list of servers, assign the connection request to the target server, and enable the target server to establish a connection with the second client 100.
The registry 600 may be a registry 600 implemented based on the Eureka framework, that is, the registry 600 may be the Eureka registry 600, or a service registry 600 such as ZooKeeper. Among them, the Eureka preferentially guarantees availability at the time of design, and the availability of the registration service can be guaranteed using the Eureka registry 600.
In the message pushing system provided in this embodiment, when receiving a message pushing request for requesting to push a message to a first client, a proxy server broadcasts a broadcast message carrying the message pushing request to a server cluster, so that a WebSocket server in the server cluster pushes the WebSocket message corresponding to the message pushing request to the first client when determining that connection information of the first client is stored according to the message pushing request carried in the broadcast message, which can effectively improve a search speed compared with a manner of querying a WebSocket server executing a message pushing task in a record including connections of all clients.
Fig. 2 is a schematic flowchart of a message processing method according to an embodiment of the present invention, and as shown in fig. 2, the method according to the embodiment may include the following steps:
s110, the proxy server receives a message pushing request for requesting to push a message to the first client.
Specifically, the client may send a message push request to the server cluster to request the server cluster to push the WebSocket message to other clients (referred to herein as the first client). The proxy server is used as a bridge for connecting the client and the server cluster, receives the message pushing request at the moment, and finds out the corresponding WebSocket server to execute the message pushing request.
The message push request may include identity information of the first client, where the identity information may be stored in a Cookie (data stored on a local terminal of the user), and a user of the client may manually edit an input number or an account as the identity information of the client.
In addition, the message pushing request can also comprise a message type of the Websocket message requested to be pushed or a specific Websocket message, so that the diversified requirements of the Websocket message requested to be pushed are met.
S120, the proxy server broadcasts the broadcast message carrying the message pushing request to the server cluster.
Specifically, after receiving the message pushing request, the proxy server may carry the message pushing request in a broadcast message and broadcast the message pushing request to the server cluster, so that the WebSocket server in the server cluster determines whether the WebSocket server stores the connection information of the first client according to the message pushing request carried in the broadcast message, if so, pushes the WebSocket message corresponding to the message pushing request to the first client, and otherwise, ignores the message pushing request.
In a specific implementation, in order to reduce the development cost, in this embodiment, the broadcast message may be broadcast through a message middleware, for example, Redis, that is, the proxy server may instruct the message middleware to broadcast the broadcast message. In view of that it is difficult for most of the existing proxy servers to directly access the message middleware, in order to further reduce development cost and improve convenience of accessing the message middleware, in this embodiment, the proxy server may access the message middleware through the execution server, that is, the proxy server may instruct the execution server to notify the message middleware to broadcast the broadcast message carrying the message push request to the server cluster.
In specific implementation, the proxy server may send an indication message to the execution server, where the indication message may carry the message push request; after receiving the indication message, the execution server can carry the message pushing request in the broadcast request message and send the message pushing request to the message middleware; after receiving the broadcast request message, the message middleware can carry the message push request in the broadcast message and broadcast the broadcast message to the server cluster.
S130, the WebSocket server receives the broadcast message.
Specifically, the WebSocket server in the server cluster subscribes to the message middleware, and after the message middleware issues the broadcast message, the WebSocket server in the server cluster can receive the broadcast message.
S140, when determining that the connection information of the first client is stored according to the message pushing request carried in the broadcast message, the WebSocket server pushes the WebSocket message corresponding to the message pushing request to the first client.
Specifically, the WebSocket server in the server cluster stores connection information of the client connected with the WebSocket server; after receiving the broadcast message, the WebSocket server can check whether the connection information of the first client is stored in the WebSocket server according to the identity information of the first client in the message pushing request; if so, indicating that the first client is the WebSocket server which needs to execute the message pushing task, pushing a WebSocket message corresponding to the message pushing request to the first client; if not, the message pushing request can be ignored if the message pushing request is not the WebSocket server which needs to execute the message pushing task.
When the connection information is specifically stored, the identity information of the client may be used as a key (key), and a channel connected to the client may be stored as a value (value). When checking whether the connection information of the first client is stored in the server, inquiring whether a key in a key-value key value pair is the identity information of the first client, if so, indicating that the server is a server for establishing connection with the first client, and pushing a WebSocket message to the first client through a channel stored in the corresponding value; if not, the connection between the first client and the second client is not established, and the message pushing request is ignored at the moment.
In addition, when the WebSocket message is specifically pushed, if the message pushing request includes a message type of the WebSocket message requesting to be pushed, the WebSocket server can push the WebSocket message corresponding to the message type to the first client; if the message pushing request comprises a specific WebSocket message, the WebSocket server can directly push the WebSocket message to the first client; if the message pushing request does not include information related to the WebSocket message, the WebSocket server can push an agreed WebSocket message to the first client.
In the message processing method provided by this embodiment, when receiving a message push request for requesting to push a message to a first client, a proxy server broadcasts a broadcast message carrying the message push request to a server cluster; after receiving the broadcast message, the WebSocket server in the server cluster pushes the WebSocket message corresponding to the message pushing request to the first client when determining that the connection information of the first client is stored according to the message pushing request carried in the broadcast message, so that the searching speed can be effectively increased compared with the mode of inquiring the WebSocket server executing the message pushing task in a record containing all client connections.
Fig. 3 is a flowchart illustrating another message processing method according to an embodiment of the present invention, where the embodiment mainly describes a connection establishment process. On the basis of the foregoing embodiment, as shown in fig. 3, the method provided in this embodiment may further include the following steps:
s210, when receiving the connection request initiated by the second client, the proxy server requests a server list from the registration center.
Specifically, when a WebSocket server in the server cluster is started, the WebSocket server can register with the registration center; the registration center may determine an online server list according to registration information of a WebSocket server started (i.e., in an online state) in the server cluster.
When receiving a connection request initiated by a new client (referred to as a second client), the proxy server may obtain a list of WebSocket servers available for invocation from the registry, so as to allocate a WebSocket server to the second client.
The connection request may include information such as identity information of the second client, an Internet Protocol (IP) address, and a port number.
S220, the registration center returns a server list to the proxy server.
Specifically, the registration center includes registration information of the WebSocket server in an online state in the server cluster, and the server list can be determined according to the registration information. The registry, upon receiving the request of the proxy server, may return the list of servers to the proxy server.
The registration information may include environment information such as an IP address and a port number of the WebSocket server, and may further include configuration information such as a memory size of the WebSocket server and a core number of a Central Processing Unit (CPU).
In this embodiment, when the WebSocket server in the server cluster is offline, an offline message may be sent to the registration center before offline to notify the registration center, and the registration center may delete the corresponding registration information; or the registration center can also actively detect whether the Websocket server in the server cluster is online at regular time, and delete the corresponding registration information when detecting that the Websocket server is offline.
And S230, after receiving the server list, the proxy server determines a target server according to the server list.
Specifically, after receiving the server list, the proxy server may determine, according to a certain balanced allocation principle, that the target server is allocated to the second client from the server list.
The equalization allocation principle may specifically be a polling principle: and distributing each connection request to different WebSocket servers one by one according to the time sequence, namely distributing the first connection request to the first WebSocket server, distributing the second connection request to the second WebSocket server … …, and distributing the (N + 1) th connection request to the first WebSocket server if N servers exist, and so on.
The balanced distribution principle may specifically be a hash principle: distributing each connection request according to a hash (hash) result of the IP of the client; the balanced allocation principle may specifically be a configuration principle: and distributing some connection requests for the high-configuration WebSocket server. Of course, the principle of the equal distribution may be other principles, and this embodiment is not particularly limited thereto.
S240, the proxy server forwards the connection request to the target server.
Specifically, after the proxy server determines the target server, the proxy server forwards the connection request to the target server.
And S250, the target server establishes connection with the second client according to the connection request and stores the connection information of the second client.
Specifically, after receiving the connection request, the target server may establish a connection with the second client according to information such as an IP address and a port number of the second client in the connection request. After the connection is established, the connection information of the second client may be stored.
And S260, when the connection between the target server and the second client is disconnected, deleting the connection information of the second client.
Specifically, when the WebSocket connection is disconnected due to the browser being closed or the network being in failure in the second client, the target server connected to the second client may receive a disconnection event sent by the second client through the proxy server, and at this time, the target server may delete the connection information of the second client.
In the message processing method provided by this embodiment, when receiving a connection request initiated by a second client, a proxy server obtains a server list available for invocation from a registry; and then, determining a target server according to the server list, and forwarding the connection request to the target server to enable the target server to establish connection with the second client according to the connection request, so that the connection request can be distributed conveniently and uniformly by the proxy server.
Based on the same inventive concept, as an implementation of the foregoing method, an embodiment of the present invention provides a message processing apparatus, where the apparatus embodiment corresponds to the foregoing method embodiment, and for convenience of reading, details in the foregoing method embodiment are not repeated in this apparatus embodiment one by one, but it should be clear that the apparatus in this embodiment can correspondingly implement all the contents in the foregoing method embodiment.
Fig. 4 is a schematic structural diagram of a message processing apparatus according to an embodiment of the present invention, where the apparatus may be integrated in a proxy server, and as shown in fig. 4, the message processing apparatus 110 according to this embodiment may include:
a receiving module 111, configured to receive a message push request for requesting to push a message to a first client;
the processing module 112 is configured to broadcast a broadcast message carrying a message push request to the server cluster, where the broadcast message is used to instruct a WebSocket server at a web port in the server cluster to push a WebSocket message corresponding to the message push request to a first client when determining that connection information of the first client is stored according to the message push request carried in the broadcast message.
As an optional implementation manner of the embodiment of the present invention, the processing module 112 is specifically configured to:
and instructing the execution server to notify the message middleware to broadcast the broadcast message carrying the message push request to the server cluster.
As an optional implementation manner of the embodiment of the present invention, the message middleware is a Redis information publishing end.
As an optional implementation manner of the embodiment of the present invention, the apparatus further includes:
an obtaining module 113, configured to obtain a server list from a registration center when the receiving module 111 receives a connection request initiated by a second client, where the registration center includes registration information of a WebSocket server in an online state in a server cluster, and the server list is formed according to the registration information;
a determining module 114, configured to determine a target server according to the server list;
a sending module 115, configured to forward the connection request to the target server, so as to instruct the target server to establish a connection with the second client according to the connection request.
As an optional implementation of the embodiment of the present invention, the registry is a Eureka registry.
As an optional implementation manner of the embodiment of the present invention, the WebSocket server is a node.
The message processing apparatus provided in this embodiment may execute the above method embodiments, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 5 is a schematic structural diagram of another message processing apparatus according to an embodiment of the present invention, where the apparatus may be integrated in a WebSocket server in a server cluster, and as shown in fig. 5, the message processing apparatus 120 according to this embodiment may include:
a receiving module 121, configured to receive a broadcast message, where the broadcast message carries a message push request for requesting to push a message to a first client;
the pushing module 122 is configured to, when it is determined that the connection information of the first client is stored according to the message pushing request, push a WebSocket message corresponding to the message pushing request to the first client.
As an optional implementation manner of the embodiment of the present invention, the message push request carries identity information of the first client, and the push module 122 is specifically configured to:
and when the connection information of the first client is determined to be stored according to the identity information of the first client, pushing the WebSocket information corresponding to the message pushing request to the first client.
As an optional implementation manner of the embodiment of the present invention, the receiving module 121 is specifically configured to:
receiving a broadcast message broadcast by message middleware.
As an optional implementation manner of the embodiment of the present invention, the apparatus further includes:
and a registration module 123, configured to register with the registry at startup.
As an optional implementation manner of the embodiment of the present invention, the receiving module 121 is further configured to: receiving a connection request forwarded by the proxy server, wherein the connection request is initiated by a second client;
the device also includes: and the connection module 124 is configured to establish a connection with the second client according to the connection request, and store connection information of the second client.
As an optional implementation manner of the embodiment of the present invention, the apparatus further includes:
and a deleting module 125, configured to delete the connection information of the second client when the connection with the second client is disconnected.
As an optional implementation manner of the embodiment of the present invention, the WebSocket server is a node.
The message processing apparatus provided in this embodiment may execute the above method embodiments, and the implementation principle and the technical effect are similar, which are not described herein again.
Based on the same inventive concept, the embodiment of the invention also provides a proxy server. Fig. 6 is a schematic structural diagram of a proxy server according to an embodiment of the present invention, and as shown in fig. 6, the proxy server according to the embodiment includes: a memory 211 and a processor 212, the memory 211 being for storing computer programs; the processor 212 is adapted to perform the method according to the above-described method embodiment when the computer program is invoked.
The proxy server provided in this embodiment may execute the above method embodiments, and the implementation principle and the technical effect are similar, which are not described herein again.
Based on the same inventive concept, the embodiment of the invention also provides a WebSocket server. Fig. 7 is a schematic structural diagram of a WebSocket server provided in the embodiment of the present invention, and as shown in fig. 7, the WebSocket server provided in this embodiment includes: a memory 221 and a processor 222, the memory 221 being for storing computer programs; the processor 222 is adapted to perform the method according to the above-described method embodiment when the computer program is called.
The WebSocket server provided in this embodiment may execute the method embodiments, and the implementation principle and the technical effect are similar, which are not described herein again.
Embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method described in the above method embodiments.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media having computer-usable program code embodied in the medium.
The Processor may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). The memory is an example of a computer-readable medium.
Computer readable media include both permanent and non-permanent, removable and non-removable storage media. Storage media may implement information storage by any method or technology, and the information may be computer-readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.
Claims (21)
1. A message processing method applied to a proxy server is characterized by comprising the following steps:
receiving a message pushing request for requesting to push a message to a first client;
and broadcasting a broadcast message carrying the message pushing request to a server cluster, wherein the broadcast message is used for indicating a web port WebSocket server in the server cluster to push a WebSocket message corresponding to the message pushing request to the first client when determining that the connection information of the first client is stored according to the message pushing request carried in the broadcast message.
2. The method of claim 1, wherein the broadcasting the broadcast message carrying the message push request to the server cluster comprises:
and instructing the execution server to notify the message middleware to broadcast the broadcast message carrying the message pushing request to the server cluster.
3. The method of claim 2, wherein the message middleware is a Redis information publisher.
4. The method of claim 1, further comprising:
when a connection request initiated by a second client is received, acquiring a server list from a registration center, wherein the registration center comprises registration information of a WebSocket server in an online state in the server cluster, and the server list is formed according to the registration information;
determining a target server according to the server list;
and forwarding the connection request to a target server to indicate the target server to establish connection with the second client according to the connection request.
5. The method of claim 4, wherein the registry is a Eureka registry.
6. The method of any of claims 1-5, wherein the WebSocket server is a node.
7. A message processing method is applied to a web port Websocket server in a server cluster, and is characterized by comprising the following steps:
receiving a broadcast message, wherein the broadcast message carries a message pushing request for requesting to push a message to a first client;
and when the connection information of the first client is determined to be stored according to the message pushing request, pushing the WebSocket message corresponding to the message pushing request to the first client.
8. The method according to claim 7, wherein the message push request carries identity information of the first client, and when it is determined that connection information of the first client is stored according to the message push request, pushing a WebSocket message corresponding to the message push request to the first client includes:
and when the connection information of the first client is determined to be stored according to the identity information of the first client, pushing the WebSocket information corresponding to the message pushing request to the first client.
9. The method of claim 7, wherein receiving the broadcast message comprises:
receiving a broadcast message broadcast by message middleware.
10. The method of claim 7, further comprising:
registering with a registry at startup.
11. The method of claim 7, further comprising:
receiving a connection request forwarded by a proxy server, wherein the connection request is initiated by a second client;
and establishing connection with the second client according to the connection request, and storing the connection information of the second client.
12. The method of claim 11, further comprising:
and when the connection with the second client is disconnected, deleting the connection information of the second client.
13. The method of any of claims 7-12, wherein the WebSocket server is a node.
14. A message processing apparatus applied to a proxy server, comprising:
the receiving module is used for receiving a message pushing request for requesting to push a message to a first client;
and the processing module is used for broadcasting a broadcast message carrying the message pushing request to a server cluster, and the broadcast message is used for indicating a web port WebSocket server in the server cluster to push a WebSocket message corresponding to the message pushing request to the first client when determining that the connection information of the first client is stored according to the message pushing request carried in the broadcast message.
15. A message processing device applied to a web port Websocket server in a server cluster is characterized by comprising:
the system comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving a broadcast message, and the broadcast message carries a message pushing request for requesting to push a message to a first client;
and the pushing module is used for pushing the WebSocket message corresponding to the message pushing request to the first client when the connection information of the first client is determined to be stored according to the message pushing request.
16. A proxy server, comprising: a memory for storing a computer program and a processor; the processor is adapted to perform the method of any of claims 1-6 when the computer program is invoked.
17. A web port WebSocket server, comprising: a memory for storing a computer program and a processor; the processor is adapted to perform the method of any of claims 7-13 when the computer program is invoked.
18. A message processing system, comprising: the client, the server cluster and the proxy server as claimed in claim 16, wherein a plurality of WebSocket servers as claimed in claim 17 are included in the server cluster.
19. The system of claim 18, further comprising: the execution server is used for notifying the message middleware to broadcast the broadcast message carrying the message pushing request to the server cluster according to the indication of the proxy server.
20. The system of claim 18 or 19, further comprising: the registry is used for providing a server list for the proxy server, wherein the registry comprises registration information of the WebSocket server in an online state in the server cluster, and the server list is formed according to the registration information.
21. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-13.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910998278.5A CN112769671B (en) | 2019-10-21 | 2019-10-21 | Message processing method, device and system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910998278.5A CN112769671B (en) | 2019-10-21 | 2019-10-21 | Message processing method, device and system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112769671A true CN112769671A (en) | 2021-05-07 |
CN112769671B CN112769671B (en) | 2023-04-18 |
Family
ID=75691648
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910998278.5A Active CN112769671B (en) | 2019-10-21 | 2019-10-21 | Message processing method, device and system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112769671B (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113452774A (en) * | 2021-06-25 | 2021-09-28 | 睿视(苏州)视频科技有限公司 | Message pushing method, device, equipment and storage medium |
CN115086292A (en) * | 2022-06-15 | 2022-09-20 | 浙江省标准化研究院(金砖国家标准化(浙江)研究中心、浙江省物品编码中心) | Distributed instant server push scheme architecture design method, device and storage medium |
CN115801716A (en) * | 2022-11-01 | 2023-03-14 | 浪潮软件科技有限公司 | Method and device for supporting multi-node instant messaging |
CN115866058A (en) * | 2022-12-02 | 2023-03-28 | 用友网络科技股份有限公司 | Flow scheduling system, operation method and device thereof and readable storage medium |
CN115914241A (en) * | 2022-09-27 | 2023-04-04 | 重庆富民银行股份有限公司 | Registration center system based on opensnips |
Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6134531A (en) * | 1997-09-24 | 2000-10-17 | Digital Equipment Corporation | Method and apparatus for correlating real-time audience feedback with segments of broadcast programs |
US20090047932A1 (en) * | 2005-11-01 | 2009-02-19 | Mcnamara Justin | Cell broadcast via encoded message to an embedded client |
CN101753712A (en) * | 2008-11-28 | 2010-06-23 | Lg电子株式会社 | Mobile terminal and method of purchasing broadcast product therein |
US20120117594A1 (en) * | 2010-11-05 | 2012-05-10 | Net & Tv, Inc. | Method and apparatus for providing converged social broadcasting service |
CN106131702A (en) * | 2016-07-29 | 2016-11-16 | 上海幻电信息科技有限公司 | Barrage supplying system and method |
US20180070152A1 (en) * | 2015-04-07 | 2018-03-08 | Lg Electronics Inc. | Broadcast signal transmission apparatus, broadcast signal reception apparatus, broadcast signal transmission method, and broadcast signal reception method |
CN108377247A (en) * | 2018-03-08 | 2018-08-07 | 北京车和家信息技术有限公司 | A kind of information push method and device |
CN108390881A (en) * | 2018-02-27 | 2018-08-10 | 北京焦点新干线信息技术有限公司 | A kind of distribution high concurrent real-time messages method for pushing and system |
CN108683653A (en) * | 2018-05-07 | 2018-10-19 | 常熟市第人民医院 | A kind of active message push system based on WebSocket |
CN109600452A (en) * | 2018-12-29 | 2019-04-09 | 北京车和家信息技术有限公司 | Server cluster, information push method and associated server |
CN109636165A (en) * | 2018-12-04 | 2019-04-16 | 浙江诺诺网络科技有限公司 | A kind of online customer service queue scheduling method of decentralization |
-
2019
- 2019-10-21 CN CN201910998278.5A patent/CN112769671B/en active Active
Patent Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6134531A (en) * | 1997-09-24 | 2000-10-17 | Digital Equipment Corporation | Method and apparatus for correlating real-time audience feedback with segments of broadcast programs |
US20090047932A1 (en) * | 2005-11-01 | 2009-02-19 | Mcnamara Justin | Cell broadcast via encoded message to an embedded client |
CN101753712A (en) * | 2008-11-28 | 2010-06-23 | Lg电子株式会社 | Mobile terminal and method of purchasing broadcast product therein |
US20120117594A1 (en) * | 2010-11-05 | 2012-05-10 | Net & Tv, Inc. | Method and apparatus for providing converged social broadcasting service |
US20180070152A1 (en) * | 2015-04-07 | 2018-03-08 | Lg Electronics Inc. | Broadcast signal transmission apparatus, broadcast signal reception apparatus, broadcast signal transmission method, and broadcast signal reception method |
CN106131702A (en) * | 2016-07-29 | 2016-11-16 | 上海幻电信息科技有限公司 | Barrage supplying system and method |
CN108390881A (en) * | 2018-02-27 | 2018-08-10 | 北京焦点新干线信息技术有限公司 | A kind of distribution high concurrent real-time messages method for pushing and system |
CN108377247A (en) * | 2018-03-08 | 2018-08-07 | 北京车和家信息技术有限公司 | A kind of information push method and device |
CN108683653A (en) * | 2018-05-07 | 2018-10-19 | 常熟市第人民医院 | A kind of active message push system based on WebSocket |
CN109636165A (en) * | 2018-12-04 | 2019-04-16 | 浙江诺诺网络科技有限公司 | A kind of online customer service queue scheduling method of decentralization |
CN109600452A (en) * | 2018-12-29 | 2019-04-09 | 北京车和家信息技术有限公司 | Server cluster, information push method and associated server |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113452774A (en) * | 2021-06-25 | 2021-09-28 | 睿视(苏州)视频科技有限公司 | Message pushing method, device, equipment and storage medium |
CN113452774B (en) * | 2021-06-25 | 2022-07-12 | 睿视(苏州)视频科技有限公司 | Message pushing method, device, equipment and storage medium |
CN115086292A (en) * | 2022-06-15 | 2022-09-20 | 浙江省标准化研究院(金砖国家标准化(浙江)研究中心、浙江省物品编码中心) | Distributed instant server push scheme architecture design method, device and storage medium |
CN115914241A (en) * | 2022-09-27 | 2023-04-04 | 重庆富民银行股份有限公司 | Registration center system based on opensnips |
CN115914241B (en) * | 2022-09-27 | 2024-06-11 | 重庆富民银行股份有限公司 | Opensips-based registration center system |
CN115801716A (en) * | 2022-11-01 | 2023-03-14 | 浪潮软件科技有限公司 | Method and device for supporting multi-node instant messaging |
CN115801716B (en) * | 2022-11-01 | 2024-07-12 | 浪潮软件科技有限公司 | Method and device for supporting multi-node instant messaging |
CN115866058A (en) * | 2022-12-02 | 2023-03-28 | 用友网络科技股份有限公司 | Flow scheduling system, operation method and device thereof and readable storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN112769671B (en) | 2023-04-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112769671B (en) | Message processing method, device and system | |
US11343353B2 (en) | Method and system of dispatching requests in a content delivery network | |
US11159411B2 (en) | Distributed testing service | |
CN112261094B (en) | Message processing method and proxy server | |
US8935377B2 (en) | Dynamic registration of listener resources for cloud services | |
WO2017020743A1 (en) | Method and device for sharing cache data | |
US20100115031A1 (en) | System and Method For Enabling P2P Applications in a Wireless Mobile Network | |
CN110620828A (en) | File pushing method, system, device, electronic equipment and medium | |
CN111131470B (en) | Terminal device, data processing method thereof and data processing system | |
CN114036031B (en) | Scheduling system and method for resource service application in enterprise digital middleboxes | |
US8725856B2 (en) | Discovery of network services | |
CN110427266B (en) | Data redundancy architecture based on MQTT service | |
US20210314406A1 (en) | Communication Method and System under Micro-Service Architecture | |
US11706301B2 (en) | Server node selection method and terminal device | |
CN115756771B (en) | Micro-servitization front-end system, workflow scheduling method and device | |
CN106899652B (en) | Method and device for pushing service processing result | |
CN113296968B (en) | Address list updating method, device, medium and electronic equipment | |
CN112202914B (en) | Message pushing method and device | |
CN112131263B (en) | Software package acquisition method, system, device, electronic equipment and storage medium | |
CN109600452B (en) | Server cluster, message pushing method and related server | |
EP4057577B1 (en) | Addressing method and addressing apparatus | |
CN111865896A (en) | Cloud system and cloud service consumption method | |
CN113055444A (en) | File sharing method and related device thereof | |
CN107835225B (en) | Method, device and equipment for acquiring data information | |
CN112769885A (en) | Proxy broadcasting method and device based on data point subscription |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |