CN116939028A - Message pushing method, system, equipment and storage medium - Google Patents
Message pushing method, system, equipment and storage medium Download PDFInfo
- Publication number
- CN116939028A CN116939028A CN202311056734.7A CN202311056734A CN116939028A CN 116939028 A CN116939028 A CN 116939028A CN 202311056734 A CN202311056734 A CN 202311056734A CN 116939028 A CN116939028 A CN 116939028A
- Authority
- CN
- China
- Prior art keywords
- message
- server
- sent
- client
- websocket
- 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.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 46
- 238000004891 communication Methods 0.000 claims description 13
- 238000004806 packaging method and process Methods 0.000 claims description 5
- 230000004044 response Effects 0.000 claims description 5
- 238000004590 computer program Methods 0.000 claims description 4
- 238000010586 diagram Methods 0.000 description 7
- 230000006870 function Effects 0.000 description 4
- 230000007246 mechanism Effects 0.000 description 4
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000012544 monitoring process Methods 0.000 description 3
- 238000005192 partition Methods 0.000 description 3
- 230000008859 change Effects 0.000 description 2
- 230000008569 process Effects 0.000 description 2
- 238000012545 processing Methods 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 238000012790 confirmation Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000002688 persistence Effects 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Classifications
-
- 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/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/50—Network services
- H04L67/56—Provisioning of proxy services
- H04L67/568—Storing data temporarily at an intermediate stage, e.g. caching
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer And Data Communications (AREA)
Abstract
The application provides a message pushing method, a system, a device and a storage medium, wherein the method comprises the following steps: after a user triggers an event at a client in the WebSocket cluster, the client sends a request message to a server connected with the client, the server generates a message to be sent according to the request message, and sends the message to be sent to a message storage server for storage, and after the server subscribed to the message queue monitors the updated message in the message queue of the message storage server, the server subscribed to the message from the message storage server, and synchronizes the message to the client connected with each server. The application solves the problem that when the WebSocket cluster is deployed, all clients with the server cannot receive the information sent by the server, and improves the reliability and safety of the WebSocket cluster system.
Description
Technical Field
The present application relates to the field of computer communications technologies, and in particular, to a method, a system, an apparatus, and a storage medium for pushing a message.
Background
WebSocket is a network communication protocol supporting two-way communication, and after a server and a client are connected, the server can actively push a message to the client, and the client can also actively send information to the server. In the case of WebSocket cluster deployment, a server can only send a message to a client which establishes connection with the server, and services of other nodes cannot send the message.
In the prior art, when solving the problem of the HTTP cluster (Hypertext Transfer Protocol ) similar to the WebSocket cluster, two methods are included, wherein the first method is session (session) sharing solution, and session information is stored in Redis to realize sharing of the Redis; the second is to save the session of the client on the server through the IP hash algorithm.
However, since WebSocket clusters have their specificity, the solution of HTTP to the problem of clusters cannot be directly used to solve the problem of WebSocket clusters.
Disclosure of Invention
The application aims to provide a message pushing method, a system, equipment and a storage medium for overcoming the defects in the prior art, so as to solve the problem that a server in a WebSocket cluster in the prior art can only send a message to a client which is connected with the server, and the service of other nodes can not send the message.
In order to achieve the above purpose, the technical scheme adopted by the application is as follows:
in a first aspect, the present application provides a message pushing method, applied to a WebSocket cluster system, where the WebSocket cluster system includes: webSocket cluster and message storage server, webSocket cluster includes: a plurality of servers and a plurality of clients communicatively coupled to each of the servers, each of the servers communicatively coupled to the message storage server, the method comprising:
sending a request message to a first server in communication connection with a first client through the first client, wherein the first client is any client in the WebSocket cluster;
generating a message to be sent by the first server according to the request message, and sending the message to be sent to the message storage server;
storing the message to be sent into a corresponding message queue by the message storage server;
at least one second server in the WebSocket cluster acquires the message to be sent from the message storage server according to message subscription information, and sends the message to be sent to a client connected with the second server, wherein the second server is any server in the WebSocket cluster, and the message subscription information is used for indicating a target message queue subscribed by the second server.
Optionally, the obtaining, by at least one second server in the WebSocket cluster, the message to be sent from the message storage server according to the message subscription information includes:
and the second server monitors a target message queue indicated by the message subscription information, and if the target message queue is monitored to store new messages, the message to be sent is acquired from the message queue.
Optionally, the sending, by the first server, the message to be sent to the message storage server according to the request message includes:
the first server analyzes the obtained data to be pushed from the request message;
determining, by the first server, a theme to which the data to be pushed belongs according to the data to be pushed, and packaging the data to be pushed and the theme to which the data to be pushed belongs as the message to be sent.
Optionally, the message storage server stores the message to be sent in a corresponding message queue, including:
and reading the theme in the message to be sent by the message storage server, and storing the message to be sent into a message queue corresponding to the theme according to the theme.
Optionally, before the sending, by the first client, the request message to the first server, the method further includes:
and sending a connection request to the first server by the first client, and establishing connection with the first server according to a connection response of the first server to the connection request.
Optionally, the method further comprises:
adding a message to be sent to the message storage server by a third party device;
and acquiring the message to be sent from the message storage server by each server according to the message subscription information, and pushing the message to be sent to a client connected with the server.
Optionally, the message storage server is a server deployed with a Kafka service, and the Kafka service is deployed in a centralized or distributed manner.
In a second aspect, the present application provides a WebSocket cluster system, where the WebSocket cluster system includes: webSocket cluster and message storage server, webSocket cluster includes: a plurality of servers and a plurality of clients communicatively coupled to each of the servers, each of the servers communicatively coupled to the message storage server, wherein:
the method comprises the steps that a first client is used for sending a request message to a first server in communication connection with the first client, wherein the first client is any client in the WebSocket cluster;
the first server is used for generating a message to be sent according to the request message and sending the message to be sent to the message storage server;
the message storage server is used for storing the message to be sent into a corresponding message queue;
at least one second server in the WebSocket cluster is used for acquiring the message to be sent from the message storage server according to message subscription information, and sending the message to be sent to a client connected with the second server, wherein the second server is any server in the WebSocket cluster, and the message subscription information is used for indicating a target message queue subscribed by the second server.
Optionally, the second server is further configured to:
monitoring a target message queue indicated by the message subscription information, and if the target message queue is monitored to store new messages, acquiring the messages to be sent from the message queue.
Optionally, the first server is further configured to:
analyzing the obtained data to be pushed from the request message;
determining the theme of the data to be pushed according to the data to be pushed, and packaging the data to be pushed and the theme of the data to be pushed into the message to be sent.
Optionally, the message storage server is further configured to:
and reading the theme in the message to be sent, and storing the message to be sent into a message queue corresponding to the theme according to the theme.
Optionally, the first client is further configured to:
and sending a connection request to the first server, and establishing connection with the first server according to a connection response of the first server to the connection request.
Optionally, the WebSocket cluster system further includes: a third party device, wherein:
the third party device is configured to: adding a message to be sent to the message storage server;
each of the servers is configured to: and acquiring the message to be sent from the message storage server according to the message subscription information, and sending the message to be sent to a client connected with the server.
Optionally, the message storage server is a server deployed with a Kafka service, and the Kafka service is deployed in a centralized or distributed manner.
In a third aspect, the present application provides an electronic device, comprising: a processor, a storage medium, and a bus, the storage medium storing machine-readable instructions executable by the processor, the processor and the storage medium communicating over the bus when the electronic device is running, the processor executing the machine-readable instructions to perform steps of a message pushing method as described above.
In a fourth aspect, the present application provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of a message pushing method as described above.
The beneficial effects of the application are as follows: each server in the WebSocket cluster is connected with the message storage server, after a client triggers an event, the client sends a request message to the server connected with the client, the server generates a message to be sent according to the request message, the message to be sent is sent to the message storage server for storage, and after the rest servers monitor the updated message in the message queue of the message storage server, the rest servers can subscribe the message from the message storage server and synchronize the message with the clients connected with each server. The application solves the problem that when the WebSocket cluster is deployed, all clients with the server cannot receive the information sent by the server, and improves the reliability and safety of the WebSocket cluster system.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 shows a schematic architecture diagram of a WebSocket cluster system according to an embodiment of the present application;
fig. 2 shows a flowchart of a message pushing method provided by an embodiment of the present application;
FIG. 3 shows a flowchart of a Kafka subscription mechanism provided by an embodiment of the present application;
FIG. 4 is a flow chart of generating a message to be sent according to an embodiment of the present application;
fig. 5 shows a flowchart of pushing a message to be sent according to an embodiment of the present application;
fig. 6 shows a schematic structural diagram of a WebSocket cluster system according to an embodiment of the present application;
fig. 7 shows a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present application, and it should be understood that the drawings in the present application are for the purpose of illustration and description only and are not intended to limit the scope of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. A flowchart, as used in this disclosure, illustrates operations implemented according to some embodiments of the present application. It should be understood that the operations of the flow diagrams may be implemented out of order and that steps without logical context may be performed in reverse order or concurrently. Moreover, one or more other operations may be added to or removed from the flow diagrams by those skilled in the art under the direction of the present disclosure.
In addition, the described embodiments are only some, but not all, embodiments of the application. The components of the embodiments of the present application generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the application, as presented in the figures, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by a person skilled in the art without making any inventive effort, are intended to be within the scope of the present application.
It should be noted that the term "comprising" will be used in embodiments of the application to indicate the presence of the features stated hereafter, but not to exclude the addition of other features.
In WebSocket cluster deployment, a server can only send a message to a client connected with the server, services of other nodes cannot send the message, and in a use scene of real-time synchronization of emergency data, emergency messages, such as states of emergency events, use of emergency resources, notification of emergency information and the like, are often required to be synchronized to all clients in the cluster, in which case the current WebSocket cluster cannot synchronize the emergency messages to all clients in the cluster.
In the prior art, when solving the problem of the cluster, the adopted solution of the HTTP similar to the WebSocket cluster comprises two modes, wherein the first mode is session (session) sharing solution, and the second mode is adopting an IP hash algorithm.
In the first mode, after the client logs in the server, the session information is stored in the Redis database, and when other servers are connected, the session is acquired from the Redis, namely the session information is stored in the Redis, so that the sharing of the Redis is realized.
However, the premise that the session can be shared is that the session of WebSocket cannot be serialized, because the session of HTTP records the requested data, and the session of WebSocket corresponds to a connection, and thus is connected to a different server, the session is also different, and thus the session of WebSocket cannot be serialized.
In the second way, the HTTP uses the IP hash algorithm of nginnx load balancing, the client requests the same server each time, the session of the client is stored on the server, the subsequent requests request the server, and the session can be obtained, so that the problem of distributed session does not exist.
However, compared with HTTP, webSocket can actively push a message to a client, if the server receiving the message and the server sending the message are not the same server, the server sending the message cannot find the session corresponding to the received message, i.e. the two sessions are not in the same server, and thus cannot push the message.
Therefore, how to ensure that the same message is sent by all node servers to the client establishing connection with the node servers in the WebSocket cluster becomes a problem to be solved.
The method of the present application may be applied to the WebSocket cluster system shown in fig. 1, and referring to fig. 1, the WebSocket cluster system includes: webSocket cluster and message storage server, webSocket cluster includes: a plurality of servers and a plurality of clients communicatively coupled to each server, each server communicatively coupled to the message storage server.
Wherein each server may be a server. After the user triggers the message sending function through the client, the client sends a request to the corresponding server, the server receives the request and produces the message and sends the message to the message storage server for waiting to consume, all server nodes subscribing the message acquire the message from the message queue, and each server sends the message to the client which establishes connection with the server through the WebSocket. The method solves the problem that when the WebSocket cluster is deployed, all clients with the server cannot receive the information sent by the server.
The message pushing method of the present application is further described with reference to fig. 2, and the method may be applied to the WebSocket cluster system shown in fig. 1, as shown in fig. 2, and the method includes:
s201: and sending a request message to a first server in communication connection with the first client through the first client, wherein the first client is any client in the WebSocket cluster.
Referring to fig. 1, a user may trigger a message transmission function through a client to enable the client to transmit a request message to a server connected to the client.
Alternatively, the first client may be any client in the WebSocket cluster shown in fig. 1, and the first server may be a server communicatively connected to the first client.
It should be noted that, one client is only connected to one server, one server may be connected to a plurality of clients, any client connected to the server may send a message to the server, and the server may also actively push a message to the client connected to the server.
S202: and generating a message to be sent by the first server according to the request message, and sending the message to be sent to the message storage server.
As an example, after the user completes the event a on the client 1, clicking on the completion of the display interface, the client 1 may send a request message to a server connected to the client, where the request message is used to indicate that the event a is completed, and the server 1 may generate a message to be sent according to the request message, where the message to be sent is used to refresh the completion status of the event a.
Alternatively, the first server may send the generated message to be sent to the message storage server, and the message storage server stores the message in the corresponding message queue.
Alternatively, the message storage server may be a server deploying Kafka services, which is a high throughput distributed publish-subscribe messaging system that can handle all action flow data of consumers in websites. Referring to fig. 1, a server 1 transmits a message to a message queue of a Kafka server, and a server 2 reads the message transmitted by the server 1 from the Kafka server.
The deployment mode of the Kafka service is centralized deployment or distributed deployment, namely the Kafka service can be deployed on one server in a centralized manner or can be deployed on a plurality of servers in a distributed manner, and the deployment mode is not limited herein.
In the embodiment of the application, the message sent by the WebSocket server is stored through the Kafka service, so that the problem that the WebSocket client (Session) cannot be serialized and cannot be placed into Redis for sharing is solved. In addition, the Kafka service also supports a group grouping mode, can have a plurality of consumption groups, consumes the same topic message, and provides a message persistence and message consumption confirmation mechanism to ensure the non-loss of the message, thereby improving the safety, reliability and usability of WebSocket cluster communication.
S203: the message to be sent is stored by the message storage server in the corresponding message queue.
As a possible implementation manner, the message to be sent may be a message pushed to a part of the consumption group, that is, a part of the server, where the message storage server may store the message to be sent in a corresponding message queue according to the topic group of the message to be sent, so that the part of the server can subscribe to the message to be sent from the message queue.
As another possible implementation, the message to be sent may be a message pushed to all clients, at which time the message storage server may store the message to be sent in a message queue towards all servers so that all servers can subscribe to the message.
S204: at least one second server in the WebSocket cluster acquires a message to be sent from the message storage server according to message subscription information, and sends the message to be sent to a client connected with the second server, wherein the second server is any server in the WebSocket cluster, and the message subscription information is used for indicating a target message queue subscribed by the second server.
After the message to be sent is stored in the message queue of the message storage server, each server subscribed to the message queue can monitor and acquire the message to be sent from the message queue, and push the message to be sent to the clients connected with the message to be sent respectively, and if the message to be sent is related to the event, each client can refresh the event according to the message to be sent.
For example, the user a completes the event a on the client 1 and triggers the request message, the server 1 generates a message to be sent according to the request message and sends the message to be sent to the Kafka service, the Kafka service stores the message to be sent in the message queue 1, the server 2 subscribes to the message queue 1, so after monitoring the enqueuing of the message to be sent, the message to be sent can be obtained from the message queue 1 and sent to the client 1 and the client 2 connected thereto, and the client 1 and the client 2 can refresh the completion status of the event a based on the message to be sent.
Taking the real-time synchronization process of the emergency data as an example, it is assumed that the user updates the number of emergency materials on the client 1 in fig. 1, at this time, the event a indicates that the number of emergency materials changes, in order to synchronize the number of emergency materials on all clients in the cluster in time, the client 1 sends a request message to the server 1 to indicate that the number of emergency materials changes, the server 1 can generate a message to be sent according to the request message and send the message to the message storage server, the message storage server stores the message to be sent corresponding to the event in a message queue, and all servers subscribed to the queue actively read the message to be sent from the message queue and synchronize the message to be sent to all clients connected with the message queue, so that the update of the number of emergency materials is realized on the clients in the cluster.
Optionally, the message storage server may include a plurality of topic packets, where each topic packet includes at least one message queue, and the message subscription information is used to indicate topic packets subscribed to by the respective server and the message queues.
It should be noted that the second server may be any server in the WebSocket cluster, that is, the second server may be the same server or different servers from the first server, when the second server is the same server as the first server, the first client is connected to the second server, and when the second server is connected to a plurality of clients, in step S204, the second server may send the message to be sent to the rest of clients other than the first client connected to the second server.
In the embodiment of the application, each server in the WebSocket cluster is connected with the message storage server, after a client triggers an event, the client sends a request message to the server connected with the client, the server generates a message to be sent according to the request message, and sends the message to be sent to the message storage server for storage, and after the rest of servers monitor the updated message in the message queue of the message storage server, the rest of servers can subscribe the message from the message storage server and synchronize the message with the client connected with each server. The application solves the problem that when the WebSocket cluster is deployed, all clients with the server cannot receive the messages sent by the server, realizes the message synchronization of the clients in the WebSocket cluster, realizes the message synchronization of each server through the message storage server and the subscription mechanism, and improves the reliability and the safety of the WebSocket cluster system.
Next, a step of obtaining, by at least one second server in the WebSocket cluster, a message to be sent from the message storage server according to the message subscription information is described, and the step S204 includes:
and the second server monitors a target message queue indicated by the message subscription information, and if the target message queue is monitored to store new messages, the message to be sent is obtained from the message queue.
The message storage server may include a plurality of topic partitions, each topic partition corresponds to one or more consumption groups, a consumption group may be a second server in the present application, each topic partition in the message storage server includes a plurality of message queues, and the message subscription information may indicate to which consumption group each server belongs, a topic subscribed by the server in the message storage server, and each message queue corresponding to the topic.
The server can determine each message queue under the subscribed subject according to the message subscription information, monitor the number of messages in each message queue or monitor the number of the latest message, if the number of messages in the message queue is increased or the latest message number is changed, it can determine that a new message is stored in the target message queue, and acquire the latest message from the message queue as the message to be sent.
Referring to fig. 3, a Kafka message subscription mechanism is provided in the present application, where a production end, i.e. a first server in the present application, produces a message and sends the message to a Kafka queue for waiting for consumption, and a consumption end subscribing to the message queue, i.e. a second server monitors that a new message is stored in the queue, can obtain the message from the message queue and send the message to a second client connected to the second server.
Next, the step of sending, by the first server, the message to be sent to the message storage server according to the request message will be described, and as shown in fig. 4, the step S202 includes:
s401: and analyzing the obtained data to be pushed from the request message by the first server.
Optionally, the request message may include data to be pushed, and when the request message is an event related message, the data to be pushed may indicate a state change of an event, and be configured to change a state of the event on a client that receives the data to be pushed to be the same as a state of the event of the first client.
S402: determining a theme to which the data to be pushed belongs by the first server according to the data to be pushed, and packaging the data to be pushed and the theme to which the data to be pushed belongs into a message to be sent.
Optionally, the first server may determine a topic related to the data to be pushed based on the analyzed data to be pushed, and, for example, assuming that the data to be pushed is related to an early warning event, the first server may determine that the topic to which the data to be pushed belongs is an early warning event topic, and package the data to be pushed and the topic to which the data to be pushed belongs as a message to be sent.
After the first server sends the message to be sent to the message storage server, the message storage server may store the message to be sent to the message storage server in the corresponding message queue, where the step S203 includes:
and reading the theme in the message to be sent by the message storage server, and storing the message to be sent into a message queue corresponding to the theme according to the theme.
Each topic can correspond to a topic identifier, and after receiving the message to be sent, the message storage server can read the topic identifier in the message to be sent, determine a message queue corresponding to the topic according to the topic identifier, and then store the message to be sent into the message queue.
It should be noted that, a topic may correspond to a plurality of message queues, where when a message to be sent is stored in a message queue by the message storage server, the message may be written into a next message queue after one message queue is full, for example, after the message queue 1 is full, the message to be sent is stored in a first position in the message queue 2, or the message to be sent may be sequentially stored in each message queue, where the application is not limited herein.
The following is a description of the steps for establishing a connection between a server and a client before a request message is sent to the first server by the first client, where the steps include:
and sending a connection request to the first server by the first client, and establishing connection with the first server according to a connection response of the first server for the connection request.
Referring to fig. 4, which is a flowchart of establishing connection between a client and a server according to the present application, the establishment of a websocket connection includes two steps: the client sends an 'upgrade' request, which is an http request, using the http protocol. The Server returns an http 101 representing that the request was successful. The parties may then begin to communicate with each other using the WebSocket protocol.
The above is a description of the step of synchronizing the message triggered by the first client to the remaining clients, and as another possible implementation, the third party device may also store the message in the Kafka server and synchronize the message to the corresponding client, as shown in fig. 5, where the step includes:
s501: adding, by the third party device, the message to be sent to the message storage server.
Optionally, the third party device may store the message to be sent in the storage server, and the third party device may be a third party system accessing the WebSocket cluster system or a third party service, and the user may add the message to be sent to the message storage server through the third party device, so that each server in the WebSocket cluster can synchronize the message to be sent to each client connected to the server.
S502: and acquiring the message to be sent from the message storage server by each server according to the message subscription information, and sending the message to be sent to a client connected with the server.
Alternatively, after the message to be sent is stored in the message queue of the message storage server, the server subscribed to the message queue may obtain the message to be sent from the message storage server, and push the message to be sent to each client connected to the server.
It should be noted that, the step of the server obtaining the message from the message storage server and sending the message to each client connected to the message storage server in communication may be the same as the step of the second server obtaining the message to be sent from the message storage server according to the message subscription message in the step S204, which is not described herein in detail.
Based on the same inventive concept, the embodiment of the application also provides a WebSocket cluster system corresponding to the message pushing method, and because the principle of solving the problem of the system in the embodiment of the application is similar to that of the message pushing method in the embodiment of the application, the implementation of the system can refer to the implementation of the method, and the repetition is omitted.
Referring to fig. 6, a schematic diagram of a WebSocket cluster system according to an embodiment of the present application is shown, where the WebSocket cluster system includes: the WebSocket cluster 600 and the message storage server 603, the WebSocket cluster 600 includes: a plurality of servers 601 and a plurality of clients 602 communicatively connected to each server, each server 601 being communicatively connected to a message storage server 603, wherein:
the first client 6021 is configured to send a request message to a first server 6011 communicatively connected to the first client 6021, where the first client 6021 is any client in the WebSocket cluster 600;
the first server 6011 is configured to generate a message to be sent according to the request message, and send the message to be sent to the message storage server 603;
the message storage server 603 is configured to store a message to be sent in a corresponding message queue;
at least one second server 6012 in the WebSocket cluster 600 is configured to obtain a message to be sent from the message storage server 603 according to message subscription information, and push the message to be sent to a client 602 connected to the second server 6012, where the second server 6012 is any server in the WebSocket cluster 600 except the first server 6011, and the message subscription information is used to indicate a target message queue subscribed by the second server 6012.
Optionally, the second server 6012 is further configured to:
monitoring a target message queue indicated by the message subscription information, and acquiring a message to be sent from the message queue if the target message queue is monitored to store new messages.
Optionally, the first server 6011 is further configured to:
analyzing the obtained data to be pushed from the request message;
determining the theme of the data to be pushed according to the data to be pushed, and packaging the data to be pushed and the theme of the data to be pushed into a message to be sent.
Optionally, the message storage server 603 is further configured to:
and reading the theme in the message to be sent, and storing the message to be sent into a message queue corresponding to the theme according to the theme.
Optionally, the first client 6021 is further configured to:
a connection request is transmitted to the first server 6011, and a connection with the first server 6011 is established according to a connection response of the first server 6011 to the connection request.
Optionally, the WebSocket cluster system further includes: a third party device, wherein:
the third party device is configured to: adding a message to be transmitted to the message storage server 603;
each server is used for: the message to be transmitted is acquired from the message storage server 603 according to the message subscription information, and is transmitted to the client 602 connected to the server.
Alternatively, the message storage server 603 is a server where the Kafka service is deployed, where the Kafka service is deployed in a centralized or distributed manner.
The process flow of each module in the apparatus and the interaction flow between the modules may be described with reference to the related descriptions in the above method embodiments, which are not described in detail herein.
The embodiment of the application solves the problem that when the WebSocket cluster is deployed, all clients with the server cannot receive the information sent by the server, and improves the reliability and safety of the WebSocket cluster system.
The embodiment of the application also provides an electronic device, as shown in fig. 7, which is a schematic structural diagram of the electronic device provided by the embodiment of the application, and includes: a processor 701, a memory 702, and a bus. The memory 702 stores machine-readable instructions executable by the processor 701 (for example, execution instructions corresponding to the WebSocket cluster 600 and the message storage server 603 in the system in fig. 6), and when the computer device runs, the processor 701 communicates with the memory 702 through a bus, and the machine-readable instructions are executed by the processor 701 to perform the processing of the message pushing method described above.
The embodiment of the application also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program executes the steps of the message pushing method when being executed by a processor.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described system and apparatus may refer to corresponding procedures in the method embodiments, and are not repeated in the present disclosure. In the several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. The above-described apparatus embodiments are merely illustrative, and the division of the modules is merely a logical function division, and there may be additional divisions when actually implemented, and for example, multiple modules or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some communication interface, indirect coupling or communication connection of devices or modules, electrical, mechanical, or other form.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily appreciate variations or alternatives within the scope of the present application.
Claims (10)
1. The message pushing method is characterized by being applied to a WebSocket cluster system, wherein the WebSocket cluster system comprises: webSocket cluster and message storage server, webSocket cluster includes: a plurality of servers and a plurality of clients communicatively coupled to each of the servers, each of the servers communicatively coupled to the message storage server, the method comprising:
sending a request message to a first server in communication connection with a first client through the first client, wherein the first client is any client in the WebSocket cluster;
generating a message to be sent by the first server according to the request message, and sending the message to be sent to the message storage server;
storing the message to be sent into a corresponding message queue by the message storage server;
at least one second server in the WebSocket cluster acquires the message to be sent from the message storage server according to message subscription information, and sends the message to be sent to a client connected with the second server, wherein the second server is any server in the WebSocket cluster, and the message subscription information is used for indicating a target message queue subscribed by the second server.
2. The method of claim 1, wherein the obtaining, by at least one second server in the WebSocket cluster, the message to be sent from the message storage server according to message subscription information, comprises:
and the second server monitors a target message queue indicated by the message subscription information, and if the target message queue is monitored to store new messages, the message to be sent is acquired from the message queue.
3. The method of claim 1, wherein the generating, by the first server, a message to be sent from the request message comprises:
the first server analyzes the obtained data to be pushed from the request message;
determining, by the first server, a theme to which the data to be pushed belongs according to the data to be pushed, and packaging the data to be pushed and the theme to which the data to be pushed belongs as the message to be sent.
4. A method according to claim 3, wherein said storing, by the message storage server, the message to be sent into a corresponding message queue, comprises:
and reading the theme in the message to be sent by the message storage server, and storing the message to be sent into a message queue corresponding to the theme according to the theme.
5. The method of claim 1, wherein prior to the sending, by the first client, the request message to a first server communicatively coupled to the first client, further comprising:
and sending a connection request to the first server by the first client, and establishing connection with the first server according to a connection response of the first server to the connection request.
6. The method according to claim 1, wherein the method further comprises:
adding a message to be sent to the message storage server by a third party device;
and acquiring the message to be sent from the message storage server by each server according to the message subscription information, and sending the message to be sent to a client connected with the server.
7. The method according to any one of claims 1-6, wherein the message storage server is a server in which a Kafka service is deployed, and the Kafka service is deployed in a centralized or distributed manner.
8. The WebSocket cluster system is characterized by comprising: webSocket cluster and message storage server, webSocket cluster includes: a plurality of servers and a plurality of clients communicatively coupled to each of the servers, each of the servers communicatively coupled to the message storage server, wherein:
the method comprises the steps that a first client is used for sending a request message to a first server in communication connection with the first client, wherein the first client is any client in the WebSocket cluster;
the first server is used for generating a message to be sent according to the request message and sending the message to be sent to the message storage server;
the message storage server is used for storing the message to be sent into a corresponding message queue;
the at least one second server in the WebSocket cluster is configured to obtain the message to be sent from the message storage server according to message subscription information, and push the message to be sent to a client connected with the second server, where the second server is any server in the WebSocket cluster, and the message subscription information is used to indicate a target message queue subscribed by the second server.
9. An electronic device, comprising: a processor, a storage medium and a bus, the storage medium storing program instructions executable by the processor, the processor and the storage medium communicating over the bus when the electronic device is running, the processor executing the program instructions to perform the steps of the message pushing method according to any of claims 1 to 7 when executed.
10. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps of the message pushing method according to any of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311056734.7A CN116939028A (en) | 2023-08-21 | 2023-08-21 | Message pushing method, system, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311056734.7A CN116939028A (en) | 2023-08-21 | 2023-08-21 | Message pushing method, system, equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116939028A true CN116939028A (en) | 2023-10-24 |
Family
ID=88392557
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311056734.7A Pending CN116939028A (en) | 2023-08-21 | 2023-08-21 | Message pushing method, system, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116939028A (en) |
-
2023
- 2023-08-21 CN CN202311056734.7A patent/CN116939028A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9578081B2 (en) | System and method for providing an actively invalidated client-side network resource cache | |
US8799400B2 (en) | System and method for managing multiple queues of non-persistent messages in a networked environment | |
US7693958B2 (en) | Instant messaging with data sharing | |
US20140372516A1 (en) | System and method for providing a scalable translation between polling-based clients and connection-based message queues | |
CN112118315A (en) | Data processing system, method, device, electronic equipment and storage medium | |
CN111277629A (en) | High-availability-based web high-concurrency system and method | |
CN110120961B (en) | Distributed service cluster and route synchronization method thereof | |
CN115004673B (en) | Message pushing method, device, electronic equipment and computer readable medium | |
CN103581276A (en) | Cluster management device and system, service client side and corresponding method | |
CN113157449A (en) | Real-time stream data analysis processing method based on MQTT | |
WO2009049380A1 (en) | Presence-awareness for wireless devices | |
CN108540367B (en) | Message processing method and system | |
CN113923397B (en) | Conference room equipment state detection method and device, electronic equipment and storage medium | |
CN114328618A (en) | Cache data synchronization method, device, equipment and storage medium | |
CN113630366A (en) | Internet of things equipment access method and system | |
CN114185582A (en) | Automobile software online upgrading system and method based on QUIC protocol | |
CN114025002A (en) | MQTT information transmission method, system and communication equipment | |
CN113507498A (en) | Government affair hall device data exchange method and model | |
CN111049915A (en) | Message queue agent grid under container cloud and method | |
CN103312586B (en) | A kind of method of instant messaging, system and server | |
US10958712B2 (en) | Enhanced reliability for information services | |
CN116939028A (en) | Message pushing method, system, equipment and storage medium | |
CN108076111B (en) | System and method for distributing data in big data platform | |
CN114827171B (en) | Information synchronization method, apparatus, computer device and storage medium | |
CN110933150A (en) | Data synchronization method, system, device, electronic equipment and computer storage medium |
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 |