Method and system for automatically reminding processing work in cluster environmentTechnical Field
The invention belongs to the technical field of server side message pushing, and particularly relates to a method and a system for realizing a server message pushing mechanism in a cluster mode.
Background
The statements in this section merely provide background information related to the present disclosure and may not necessarily constitute prior art.
In Web applications, when a client, such as a browser, needs to obtain latest background data immediately and display the latest background data to a user, a polling mode is usually adopted, and such polling requests are mostly invalid (possibly, background data does not change) and are relatively weak in instantaneity, and pressure on foreground and background is relatively large.
In the prior art, no matter whether background data changes or not, polling is performed on the data from the background all the time, for example, the data is taken once every 5 seconds, when the background data changes within 5 seconds, the data cannot be displayed immediately due to the need of waiting for 5 seconds, and the data can be displayed after being taken by polling processing after 5 seconds. In addition, if the polling is performed 12 times without changing the background data within 1 minute, the 12 times of data fetching are the same, so the 12 times of data fetching are invalid.
With the continuous development of the information-based society, timely and accurate information acquisition plays a very important role in the correct decision of people, and also provides new requirements for various technologies.
Disclosure of Invention
In order to overcome the defects of the prior art, the invention provides a method for realizing a server message pushing mechanism in a cluster mode, which not only can realize the communication among cluster nodes, but also can meet the requirement that a server actively pushes messages to a client under a cluster environment, meet the requirement of instantaneity and reduce the pressure on foreground and background caused by polling.
In order to achieve the above object, one or more embodiments of the present invention provide the following technical solutions:
a method for automatically reminding processing work in cluster environment comprises the following steps:
logging in a web application system through a client browser, and realizing event-driven communication between a client and a server by using a long-term http connection;
the client sends the information request to the server by adding various subject message types needing to be subscribed, and the client browser receives the data actively sent by the server and displays the data.
The technical scheme is that a client logs in an application system, an activemq configuration item is loaded after a project is started, two message destinations are generated in spring and used for pushing messages to the activemq when the messages are sent, one is a queue destination, and the other is a theme destination; and loading a listener for monitoring the queue and the theme in the message middleware at the same time, and immediately receiving and processing the message when a new message exists.
According to the further technical scheme, after the server side generates data needing to be pushed, the server side analyzes the data to obtain a receiving object and pushes an appointed client side, a set destination and a message body are pushed to activemq through a public method, and the activemq stores the data in a table after receiving the message and waits for a listener to read the data.
In a further technical scheme, after finding the message to be processed, the client monitor reads the message from the activemq, and the activemq automatically determines whether to empty the message according to the type of the message, namely the queue or the theme.
According to the further technical scheme, after a monitor obtains a message, a message body is analyzed to obtain message content and receiver information, an online user list is obtained through a pushlet, a message receiver in the online user list is found out, the message is pushed to a client browser in real time, if a user corresponding to the client browser is not online, the message is persisted to a database, and after the message is online, a message to be processed is searched and displayed to the user.
According to the further technical scheme, after the client side has the message to be processed, the system sets the message to be in a read state after the message is processed by clicking, and the read message is not displayed after logging in again.
In the further technical scheme, the client logs out of the system to cancel the subscription, logs out the session and does not receive the message any more.
A system for automatically alerting processing jobs in a clustered environment, comprising: a client and a server;
logging in a system through a client, and realizing event-driven communication between the client and a server by using a long-term http connection;
and the server receives a subscription request added by a client user as required, and displays the push data to a specified client browser.
The above one or more technical solutions have the following beneficial effects:
the client user is free from installing any software, and only a browser is needed: pushlet is a Servlet-based mechanism for realizing a comet architecture, and data is directly pushed (push) from a Java object at a server end to a (dynamic) HTML page of a browser at a client end without any Java applet or plug-in, so that a user is free from installing any software.
The client side displays multiple styles of effects. The display of the messages on the browser is in seamless connection with the javascript, the received and displayed messages are completely composed of js and html elements, and the browser can form various display effects according to needs after receiving the messages.
And meets the requirement of instantaneity. The pushlet message is sent by using an http protocol, and under the condition of good network state, the online user hardly perceives the time consumed in the data circulation process. Activemq is also on the order of milliseconds, with almost negligible time from sending a message to receiving it.
The effectiveness of the message is improved. The ordinary polling method is most of the cases where the acquired message data is invalid. When the patent is used for sending a message to a user, the message is triggered when new data are generated or changed based on the exact requirement, so that the one-hundred-percent validity of the data is ensured.
The technical scheme of the application can solve the problem that the latest data cannot be obtained in the polling interval in the background technology, and can be immediately pushed and displayed without waiting as long as data change exists.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, are included to provide a further understanding of the invention, and are incorporated in and constitute a part of this specification, illustrate exemplary embodiments of the invention and together with the description serve to explain the invention and not to limit the invention.
FIG. 1 is a schematic diagram of a user login system according to an embodiment of the present invention;
FIG. 2 is a diagram illustrating boot loading according to an embodiment of the present invention;
fig. 3 is a schematic diagram of message pushing according to an embodiment of the present invention.
Detailed Description
It is to be understood that the following detailed description is exemplary and is intended to provide further explanation of the invention as claimed. Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
It is noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of exemplary embodiments according to the invention. As used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, and it should be understood that when the terms "comprises" and/or "comprising" are used in this specification, they specify the presence of stated features, steps, operations, devices, components, and/or combinations thereof, unless the context clearly indicates otherwise.
The embodiments and features of the embodiments of the present invention may be combined with each other without conflict.
Example one
The embodiment discloses a method for automatically reminding processing work in a cluster environment, which not only can realize communication among cluster service nodes, but also can meet the requirement that a server actively pushes a message to a client in the cluster environment, and reduce the pressure on foreground and background caused by polling while meeting the requirement on instantaneity.
In an embodiment, referring to fig. 1, a user logs in an application system, and uses a jsp/servlet technology to implement event-driven communication between a client and a server by using a long-term http connection. The user is identified by adding a unique TOKEN in the cookie, and the user adds a pushlet in the client through the TOKEN identity and listens to various subject messages. Background service defines multiple types of theme message types, a user joins in and subscribes different types of themes according to needs to receive different types of messages, a server side sends messages to a specified client side according to TOKEN, and the client side can display the messages instantly when monitoring new messages.
Referring to fig. 2, after the background server is started, an activemq configuration item is loaded to generate two message destinations in spring for pushing a message to the activemq when sending the message, one is that only one person can receive the message at the queue destination, and the other is that multiple persons at the subject destination can receive the message; and meanwhile, loading a listener for monitoring the queue and the theme in the message middleware, and immediately receiving and processing the message when a new message exists.
After the background generates data to be pushed, people needing to be pushed find the corresponding TOKEN, a destination, a message body and a receiver are set in a json format, the data are pushed to activemq through a public method, the activemq analyzes the data after receiving the message, and the data are stored in a table and wait for a listener in the background cluster node to read.
Referring to fig. 3, after finding the message to be processed, the listener reads the message from activemq, and the activemq automatically determines whether to empty the message according to the type of the message, i.e., whether the message is a queue or a topic. After a listener acquires a message, a message body is analyzed to acquire message content and receiver information, an online user list is acquired through TOKEN, a message receiver in the online user list is found out, the message is instantly pushed to a user, if the user is not found in pushlet monitoring, namely the user is not online, the message is persisted to a database, and after the user is online, a message to be processed is searched and displayed to the user.
After finding the message to be processed, the user clicks the message processing system to set the message to be in a read state, and the read message is not displayed after logging in again.
The user logs out of the system to cancel the subscription, logs out the session and does not accept the message any more.
Example two
The present embodiment aims to provide a system for automatically reminding processing work in a cluster environment, including: a client and a server;
logging in a system through a client, and realizing event-driven communication between the client and a server by using a long-term http connection;
and the server receives the subscription added by the client user as required, and displays the push data after the push data is sent to the specified client browser.
After the server side generates data needing to be pushed, according to the received client side needing to be pushed, a destination and a message body are set to be pushed to activemq through a public method, and after the activemq receives the message, the data are stored in a table to wait for a listener to read.
After finding the message to be processed, the client monitor reads the message from the activemq, and the activemq automatically determines whether to empty the message according to the type of the message, namely the queue or the theme;
after a listener acquires a message, a message body is analyzed to acquire message content and receiver information, an online user list is acquired through a pushlet, a message receiver in the online user list is found out, the message is instantly pushed to a client browser, if a user corresponding to the client browser is not online, the message is duralized to a database, and after the message is online, a message to be processed is searched and displayed to the user.
For the specific information processing procedure of the client and the server, refer to the detailed description of the first embodiment.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Although the embodiments of the present invention have been described with reference to the accompanying drawings, it is not intended to limit the scope of the present invention, and it should be understood by those skilled in the art that various modifications and variations can be made without inventive efforts by those skilled in the art based on the technical solution of the present invention.