CN115334066A - Distributed cluster system and method for processing synchronous request response - Google Patents

Distributed cluster system and method for processing synchronous request response Download PDF

Info

Publication number
CN115334066A
CN115334066A CN202211250376.9A CN202211250376A CN115334066A CN 115334066 A CN115334066 A CN 115334066A CN 202211250376 A CN202211250376 A CN 202211250376A CN 115334066 A CN115334066 A CN 115334066A
Authority
CN
China
Prior art keywords
node
service cluster
message
processing
equipment
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
Application number
CN202211250376.9A
Other languages
Chinese (zh)
Other versions
CN115334066B (en
Inventor
陆舟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Feitian Technologies Co Ltd
Original Assignee
Feitian Technologies Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Feitian Technologies Co Ltd filed Critical Feitian Technologies Co Ltd
Priority to CN202211250376.9A priority Critical patent/CN115334066B/en
Publication of CN115334066A publication Critical patent/CN115334066A/en
Application granted granted Critical
Publication of CN115334066B publication Critical patent/CN115334066B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network

Abstract

The invention discloses a distributed cluster system and a method for processing synchronous request response thereof, wherein the system comprises a WEB front end, a communication service cluster, a message queue, a business service cluster and an equipment service cluster, wherein the communication service cluster, the business service cluster and the equipment service cluster all comprise a plurality of nodes, and the node which is communicating is a first node. Processing results and information are stored in the message queue through the nodes of the service cluster, and each node of the communication service cluster actively goes to the message queue to acquire data and finds out the data required by the node and returns the data to the WEB front end, so that the complexity of the distributed cluster system in the process of converting asynchronous requests into synchronous requests can be simplified, the dependence between the calls of the distributed system is reduced, and the decoupling is more thorough and efficient; meanwhile, the development, deployment and maintenance costs are saved, the complexity of service processing and the resource consumption are reduced, and the overall processing efficiency and performance of the system are improved.

Description

Distributed cluster system and method for processing synchronous request response
Technical Field
The present invention relates to the field of information security, and in particular, to a distributed cluster system and a method for processing a synchronization request response thereof.
Background
In order to not affect the synchronous processing logic of an API (Application Programming Interface, chinese full name: application program Interface) upstream system in the current industry, a background distributed cluster service (such as a communication service) cannot return immediately after calling a third-party service (such as a business service), and needs to wait for a result notification until a specific return result is obtained. This requires that the background service internally converts asynchronization into synchronization, and the technical solution adopted in the prior art is as follows: the socket server is used for constructing a service receiving program, when the service receiving program receives the notification of the service, the result is forwarded to the communication service through the socket server, and because accurate forwarding is needed, some shared storage is needed to record the forwarded service address and configuration, so that the maintenance is troublesome, and the system complexity is high.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides a distributed cluster system and a method for processing synchronous request responses.
In a first aspect, an embodiment of the present invention provides a method for processing a synchronization request response in a distributed cluster system, which is applicable to a system including a WEB front end, a communication service cluster, a message queue, a service cluster, and an equipment service cluster, where the communication service cluster, the service cluster, and the equipment service cluster all include multiple nodes, and a node in communication is a first node, where the method includes:
when the WEB front end receives a processing request triggered by a user, sending the processing request to a first node of the communication service cluster according to a first preset rule;
when the first node of the communication service cluster detects that the processing request is sent by the WEB front end, starting a first thread, receiving the processing request through the first communication channel of Cheng Chuangjian by the first line, judging whether a request parameter in the processing request is legal or not, if not, sending interface error information to the WEB front end through the first communication channel, if so, forming a new processing instruction according to an interface name and equipment number in the request parameter and the generated service ID, and sending the new processing instruction to the first node of the service cluster according to a second preset rule;
when the first node of the communication service cluster receives success information returned by the first node of the business service cluster, correspondingly storing the generated business ID and the first communication channel, and suspending the first communication channel;
when any node of the communication service cluster detects that data exists in the message queue, acquiring the data from the message queue through a mode of broadcasting messages, judging whether the acquired data needs to be processed, if so, waking up a first communication channel corresponding to a service ID in the acquired data, and sending the acquired data to the WEB front end through the woken up first communication channel, otherwise, discarding the acquired data;
when the first node of the business service cluster receives the new processing instruction sent by the first node of the communication service cluster, the first node of the communication service cluster returns success information, interface parameters are obtained from the new processing instruction, the IP of a server where the long connection of the equipment corresponding to the equipment number in the interface parameters is located is obtained, a processing message is generated according to the interface name and the business ID in the interface parameters, and the processing message is sent to the first node corresponding to the obtained IP in the equipment service cluster;
when the first node of the business service cluster receives a processing result sent by the first node of the equipment service cluster, storing the processing result in the message queue;
when the first node of the equipment service cluster receives a processing message sent by the first node of the business service cluster, sending the processing message to a long-connection terminal device;
and when the first node of the equipment service cluster receives the processing result returned by the terminal equipment, sending the processing result to the first node of the business service cluster.
In a second aspect, an embodiment of the present invention further provides a distributed cluster system, including: the system comprises a WEB front end, a communication service cluster, a message queue, a business service cluster and an equipment service cluster, wherein the communication service cluster, the business service cluster and the equipment service cluster all comprise a plurality of nodes, and the node which is communicating is a first node;
the WEB front end is used for sending a processing request to a first node of the communication service cluster according to a first preset rule when receiving the processing request triggered by a user;
the first node of the communication service cluster is used for starting a first thread when detecting that the processing request is sent by the WEB front end, receiving the processing request through the first communication channel by the first thread Cheng Chuangjian, judging whether a request parameter in the processing request is legal or not, if not, sending interface error information to the WEB front end through the first communication channel, if so, forming a new processing instruction according to an interface name and equipment number in the request parameter and the generated service ID, and sending the new processing instruction to the first node of the service cluster according to a second preset rule;
the first node of the communication service cluster is further configured to, when receiving success information returned by the first node of the service cluster, correspondingly store the generated service ID and the first communication channel, and suspend the first communication channel;
any node of the communication service cluster is further configured to, when detecting that there is data in the message queue, acquire the data from the message queue in a broadcast message mode, and determine whether the acquired data needs to be processed, if so, wake up a first communication channel corresponding to a service ID in the acquired data, send the acquired data to the WEB front end through the woken up first communication channel, and otherwise, discard the acquired data;
the first node of the business service cluster is used for returning success information to the first node of the communication service cluster when receiving the new processing instruction sent by the first node of the communication service cluster, acquiring an interface parameter from the new processing instruction, acquiring an IP of a server where a long connection of a device corresponding to the device number in the interface parameter is located, generating a processing message according to the interface name and the business ID in the interface parameter, and sending the processing message to the first node corresponding to the acquired IP in the device service cluster;
the first node of the business service cluster is further used for storing a processing result in the message queue when receiving the processing result sent by the first node of the equipment service cluster;
the message queue is used for storing data sent by the nodes of the business service cluster;
the first node of the equipment service cluster is used for sending the processing message to the long-connection terminal equipment when receiving the processing message sent by the first node of the business service cluster;
and the first node of the equipment service cluster is also used for sending the processing result to the first node of the business service cluster when receiving the processing result returned by the terminal equipment.
In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes at least one processor, a memory, and instructions stored on the memory and executable by the at least one processor, and the at least one processor executes the foregoing method for processing a synchronization request response by a distributed cluster system.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, which includes a computer program, when the computer program runs on an electronic device, causing the electronic device to execute the foregoing method for processing a synchronization request response by a distributed cluster system.
In a fifth aspect, an embodiment of the present invention further provides a chip system, which includes a chip, where the chip is coupled to a memory, and is configured to execute a computer program stored in the memory to perform the foregoing method for processing a synchronization request response by a distributed cluster system.
Compared with the prior art, the invention has the following advantages:
the implementation scheme for synchronously returning the asynchronous service processing can simplify the complexity of the distributed cluster system in the process of converting the asynchronous request into the synchronous request, reduce the dependence between calls of the distributed system, and realize more thorough decoupling and high efficiency; meanwhile, the development, deployment and maintenance costs are saved, the complexity of service processing and the resource consumption are reduced, and the overall processing efficiency and performance of the system are improved.
Drawings
Fig. 1 is a schematic diagram of a topology structure of a distributed cluster system according to a second embodiment of the present invention;
fig. 2 is a flowchart of a method for processing a synchronization request response by a distributed cluster system according to a third embodiment of the present invention.
Detailed Description
The present application provides a distributed cluster system and a method for processing a synchronization request response thereof, and the following describes in detail a specific embodiment of the present application with reference to the accompanying drawings. Examples of which are illustrated in the accompanying drawings. The embodiments described below with reference to the drawings are exemplary only for the purpose of explaining the present application and are not to be construed as limiting the present application.
It will be understood by those within the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. It will be further understood that terms, such as those defined in commonly used dictionaries, should be interpreted as having a meaning that is consistent with their meaning in the context of the prior art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein.
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention are described in further detail below with reference to the accompanying drawings.
Example one
The embodiment of the invention provides a distributed cluster system, which comprises a WEB front end, a communication service cluster, a message queue, a business service cluster and an equipment service cluster, wherein as shown in figure 1, the communication service cluster comprises a plurality of nodes (A1, A2, A3 … …), the business service cluster comprises a plurality of nodes (B1, B2, B3 … …), the equipment service cluster comprises a plurality of nodes (C1, C2, C3 … …), the WEB front end can communicate with any node in the communication service cluster through an API (application programming interface), each node in the communication service cluster can communicate with any node in the business service cluster, each node in the business service cluster can communicate with any node in the equipment service cluster, and each node in the equipment service cluster can be connected with a plurality of terminal devices; the nodes which are in communication in the communication service cluster, the business service cluster and the equipment service cluster are collectively called as first nodes; in the process of processing a certain service, a first node of a service cluster is fixedly connected with a first node of an equipment service cluster for communication, a terminal device is in long connection with the first node of the equipment service cluster, and the first node of the service cluster and the first node of the equipment cluster are likely to be changed only after the service processing is finished;
the WEB front end is used for sending a processing request to a first node of the communication service cluster according to a first preset rule when receiving the processing request triggered by a user;
alternatively, the first preset rule in the embodiment may be any one of the following ways,
(1) And a polling method: after receiving the processing request, the load balancer sequentially allocates the processing request to the nodes of the communication service cluster, without considering the performance and load of each node, for example, the communication service cluster includes: the processing logic of the polling method is that the processing request is received for the first time and then handed to the node A1 for processing, the processing request is received for the second time and then handed to the node A2 for processing, and polling is carried out in sequence;
(2) And a random method: after receiving the processing request, the load balancer calculates a certain node allocated to the communication service cluster through a random algorithm, for example, randomly generates 0 to 10 data by using a random function, if the data is less than 5, the processing request is sent to the node A1, and if the data is more than 5, the processing request is sent to the node A2;
(3) And a weighted polling method: the configuration and the performance of different nodes are possibly different, the node with high configuration can distribute more processing requests, the weight can be configured to be higher, the node with low configuration can distribute less requests, and the weight can be configured to be lower;
(4) And a weighted random method: like the weighted round robin method, the weighted random method also assigns different weights according to the configuration and load of the nodes, except that it randomly sends processing requests to the nodes according to the weights, rather than sequentially;
(5) Source address hashing method: the source address hashing method is that a hash value is obtained through the calculation of a hash function according to the IP address of a client side where the WEB front end sending the processing request is located, the hash value and the size of the server list are subjected to modular operation, and the obtained result is the serial number of the node address to be accessed;
(6) Minimum number of links method: the load balancer acquires the link number of the node, and decides which node the processing request is allocated to according to the link number, for example, the processing request is allocated to the node with the least backlog link number;
for example, in this embodiment, the WEB front end selects a corresponding communication service according to a polling method and sends a processing request to the node A1 of the communication service cluster;
the WEB front end is also used for receiving a processing result sent by a first node of the communication service cluster;
optionally, in this embodiment, the WEB front end is further configured to perform, when receiving information sent by the first node of the communication service cluster, a corresponding prompt on the user according to a coding and processing result in the information;
optionally, in this embodiment, the WEB front end communicates with the communication service cluster through an API;
the first node of the communication service cluster is used for starting a first thread when a processing request sent by the WEB front end is detected, establishing a first communication channel through the first thread, receiving the processing request through the first communication channel, judging whether a request parameter in the processing request is legal or not, sending interface error information to the WEB front end through the first communication channel if the request parameter is legal, forming a new processing instruction according to an interface name and a device number in the request parameter and a generated service ID if the request parameter is legal, and sending the new processing instruction to the first node of the service cluster according to a second preset rule;
optionally, in this embodiment, one application corresponds to one thread, the threads created by the nodes of the communication service cluster may be one or multiple threads, and each thread may create one or multiple communication channels to perform different data communications;
the first thread started when the first node of the communication service cluster detects that the processing request is sent by the WEB front end may be created at that time or acquired from a thread pool, that is, the first node of the communication service cluster is used for starting the first thread when the processing request is sent by the WEB front end, and the method comprises the following steps: the first node of the communication service cluster is used for creating a first thread and starting the first thread when a processing request sent by a WEB front end is detected, or the first node of the communication service cluster is used for acquiring the first thread from the thread pool and starting the acquired first thread when the processing request sent by the WEB front end is detected;
a first node of the communication service cluster starts a first thread and a first communication channel of a first line Cheng Chuangjian;
in this embodiment, the request parameter includes an interface name, a device number, a random number, and a signature result, and the determining, by the first node of the communication service cluster, whether the obtained request parameter is legal includes: the first node of the communication service cluster is used for judging whether the interface name belongs to the interface name in the preset range, judging whether the format of the equipment number is correct, verifying the signature result according to the interface name, the equipment number and the random number, and judging whether the verification is successful, if yes, the request parameter is legal, otherwise, the request parameter is illegal;
optionally, in this embodiment, the format of the new processing instruction is json format;
preferably, the sending, by the first node of the communication service cluster, the new processing instruction to the first node of the business service cluster according to the second preset rule includes: the first node of the communication service cluster is used for sending a new processing instruction to the first node of the business service cluster according to a second preset rule and through a first preset mode; for example, the first preset mode is an Http POST request mode;
optionally, in this embodiment, the first node of the communication service cluster is further configured to determine whether the new processing instruction is successfully sent after sending the new processing instruction to the first node of the service cluster according to the second preset rule, send the new processing instruction to the first node of the service cluster again according to the second preset rule if the new processing instruction is not successfully sent, and determine whether the new processing instruction is successfully sent, and send the interface exception information to the WEB front end through the first communication channel if the new processing instruction is not successfully sent;
optionally, the second preset rule in this embodiment may be the same as or different from the first preset rule, and is any one of a polling method, a random method, a weighted polling method, a weighted random method, a source address hash method, and a minimum link number method;
for example, in this embodiment, the node A1 of the communication service cluster sends a new processing instruction in json format to the node B2 of the service cluster according to the minimum link number method;
the first node of the communication service cluster is also used for correspondingly storing the generated service ID and the first communication channel and suspending the first communication channel when receiving success information returned by the first node of the service cluster;
specifically, in this embodiment, the first node of the communication service cluster is further configured to correspondingly store the generated service ID and the first communication channel, and the method includes: the first node of the communication service cluster is also used for correspondingly storing the generated service ID and a reference object of the first communication channel in the communication service, and binding the first communication channel of the first thread for overtime monitoring;
if the first node of the communication service cluster closes the first communication channel after monitoring timeout, if the WEB front end communicates with the first node of the communication service cluster again, the first node of the communication service cluster needs to reestablish the first communication channel through a first thread;
in this embodiment, when the first communication channel of the first thread is suspended, the other communication channels of the first thread and the communication channels of the other threads can both normally receive, process, and send data;
each node of the communication service cluster is further used for acquiring data from the message queue in a broadcast message mode when detecting that the message queue contains the data, judging whether the acquired data needs to be processed or not, if so, waking up a first communication channel corresponding to a service ID in the acquired data, and sending the acquired data to a WEB front end through the woken up first communication channel, otherwise, discarding the acquired data;
specifically, each node of the communication service cluster is further configured to acquire data from the message queue in a broadcast message mode, and determine whether the acquired data needs to be processed, if yes, wake up a first communication channel corresponding to a service ID in the acquired data, and send the acquired data to the WEB front end through the woken up first communication channel, otherwise, discard the acquired data, including: each node of the communication service cluster is further used for acquiring message content from a message body of the message queue through a mode of broadcasting messages, searching a reference object of a first communication channel from the communication service according to a service ID in the message content, waking up the first communication channel corresponding to the service ID in the message content if the reference object is found, and sending a processing result in the message content to a WEB front end through the woken first communication channel, and discarding the acquired message content if the reference object is not found;
the first node of the business service cluster is used for returning success information to the first node of the communication service cluster when receiving a new processing instruction sent by the first node of the communication service cluster, acquiring an interface parameter from the new processing instruction, acquiring an IP (Internet protocol) of a server where a long connection of equipment corresponding to the equipment number in the interface parameter is positioned, generating a processing message according to the interface name and the business ID in the interface parameter, and sending the processing message to the first node corresponding to the acquired IP in the equipment service cluster;
optionally, in this embodiment, the step of the first node of the service cluster being configured to obtain the interface parameter from the new processing instruction and obtain the IP of the server where the long connection of the device corresponding to the device number in the interface parameter is located, further includes: the first node of the business service cluster is used for judging the business type according to the acquired interface parameters, processing according to the interface parameters if the business type is the business which does not need to be sent to the terminal equipment, and storing the processing result in a message queue, and acquiring the IP of the server where the long connection of the equipment corresponding to the equipment number in the interface parameters is located if the business type is the business which needs to be sent to the terminal equipment;
optionally, in this embodiment, acquiring an interface parameter from the new processing instruction, acquiring an IP of a server where a long connection of a device corresponding to the device number in the interface parameter is located, and generating a processing packet according to the interface name and the service ID in the interface parameter includes: acquiring interface parameters from the new processing instruction, generating a message ID, acquiring an IP of a server where the long connection of the equipment corresponding to the equipment number in the interface parameters is positioned, and generating a processing message according to the interface name, the service ID and the message ID in the interface parameters;
when a first node of a service cluster receives a new processing instruction every time, a corresponding message ID is generated when the service type is judged to be a service needing to be sent to a terminal device for processing, and the generated message IDs are different every time;
preferably, in this embodiment, the first node of the service cluster is configured to send the processing packet to the first node corresponding to the obtained IP in the device service cluster, and specifically: the first node of the business service cluster is used for sending the processing message to a first node corresponding to the acquired IP in the equipment service cluster through a first preset mode;
specifically, in this embodiment, the first node of the service cluster is configured to obtain an IP of a server where a long connection of a device corresponding to the device number in the interface parameter is located, and generate a processing packet according to the interface name and the service ID in the interface parameter, where the method includes: the first node of the service cluster is used for judging whether the state of the corresponding terminal equipment is normal or not according to the equipment number in the interface parameter, if not, the equipment abnormal message is stored in the message queue, if so, the IP of the server where the long connection of the equipment corresponding to the equipment number is located is obtained, if not, the obtained abnormal message is stored in the message queue, and if so, the processing message is generated according to the interface name and the service ID in the interface parameter;
the first node of the service cluster is configured to determine whether a state of the corresponding terminal device is normal according to a device number in the interface parameter, including: the first node of the business service cluster is used for judging whether the corresponding terminal equipment is initialized according to the equipment number, judging whether the corresponding terminal equipment is activated according to the equipment number, judging whether the state of the corresponding terminal equipment is unlocked according to the equipment number, if so, judging that the state of the corresponding terminal equipment is normal, otherwise, judging that the state of the corresponding terminal equipment is abnormal;
for example, if the service that does not need to be sent to the terminal device is a request for order checking, the detailed order information is inquired according to the order number in the interface parameter, and the found detailed order information is stored in the message queue; if the service needing to be sent to the terminal equipment is equipment information acquisition, acquiring an IP of a server where the long connection of the equipment corresponding to the equipment number is located from a database, generating an equipment information acquisition message according to an interface name and a service ID in the interface parameter and the generated message ID, and sending the equipment information acquisition message to a first node corresponding to the acquired IP in the equipment service cluster;
for example, in this embodiment, the node B2 of the service cluster sends the processing packet to the node C3 of the device service cluster in the HTTP Post request manner;
the first node of the business service cluster is also used for storing the processing result in the message queue when receiving the processing result sent by the first node of the equipment service cluster;
specifically, in this embodiment, the first node of the business service cluster is further configured to store the processing result in the message queue, where the storing includes:
the first node of the business service cluster is also used for judging whether the client of the message queue needs to be initialized, if so, the client of the message queue is initialized;
the first node of the business service cluster is further used for initializing a client of the message queue, and the client comprises: the first node of the business service cluster is also used for creating a client instance of the message queue, setting the IP of the message queue, setting retry interval time when the message is failed to be sent, setting sending overtime time and starting the client of the message queue;
the first node of the business service cluster is also used for generating a message body according to the processing result and the business ID and storing the message body in a message queue;
specifically, a first node of the service cluster generates message content according to the processing result and the service ID, assembles a message body according to the message content, stores the message body in a message queue, and records a log according to the storage result;
the message queue is used for storing data sent by the nodes of the business service cluster;
the first node of the equipment service cluster is used for sending the processing message to the long-connection terminal equipment when receiving the processing message sent by the first node of the business service cluster;
optionally, in this embodiment, the first node of the device service cluster is specifically configured to, when receiving a processing packet sent by the first node of the service cluster, obtain an interface name, a message ID, and a service ID from the processing packet, determine whether the received processing packet is processed according to the message ID, if so, report an error, otherwise, store the obtained message ID, and send the processing packet to the long-connection terminal device;
optionally, the step of storing the acquired message ID may be replaced by: replacing the stored message ID with the acquired message ID;
further, the determining, by the first node of the device service cluster, whether the received processing packet is processed according to the message ID includes: the first node of the equipment service cluster is used for judging whether the message ID is consistent with the stored message ID, if so, the message is processed, otherwise, the message is not processed;
and the first node of the equipment service cluster is also used for sending the processing result to the first node of the business service cluster when receiving the processing result returned by the terminal equipment.
In the system for synchronously returning asynchronous service processing provided by the embodiment, processing results and information are stored in the message queue through the nodes of the service cluster service, and each node of the communication service cluster actively goes to the message queue to acquire data and finds data required by the node and returns the data to the WEB front end, so that the complexity of the distributed cluster system in the process of converting asynchronous requests into synchronous requests can be simplified, the dependence between calls of the distributed system is reduced, and the decoupling is more thorough and efficient; meanwhile, the development, deployment and maintenance costs are saved, the service processing complexity and the resource consumption are reduced, and the overall processing efficiency and performance of the system are improved.
Example two
The second embodiment of the present invention provides a method for processing a synchronization request response in a distributed cluster system, which is applicable to a system including a WEB front end, a communication service cluster, a service cluster, a message queue, and an equipment service cluster, where the communication service cluster, the service cluster, and the equipment service cluster all include multiple nodes, and a node in communication is a first node, and the method includes:
when a WEB front end receives a processing request triggered by a user, sending the processing request to a first node of a communication service cluster according to a first preset rule;
optionally, in this embodiment, when the WEB front end receives the information sent by the first node of the communication service cluster, the WEB front end performs corresponding prompt to the user according to the coding and processing result in the information;
optionally, in this embodiment, the WEB front end communicates with the communication service cluster through an API;
optionally, the first preset rule in this embodiment may be any one of a polling method, a random method, a weighted polling method, a weighted random method, a source address hashing method, and a minimum link number method;
when a first node of a communication service cluster detects that a WEB front end sends a processing request, a first thread is started, a first communication channel is established through the first thread, the processing request is received through the first communication channel, whether a request parameter in the processing request is legal or not is judged, if not, interface error information is sent to the WEB front end through the first communication channel, if so, a new processing instruction is formed according to an interface name and an equipment number in the request parameter and a generated service ID, and the new processing instruction is sent to the first node of the service cluster according to a second preset rule;
optionally, in this embodiment, the first thread started when the first node of the communication service cluster detects that the processing request is sent by the WEB front end may be created at that time or acquired from a thread pool, that is, the starting the first thread when the first node of the communication service cluster detects that the processing request is sent by the WEB front end includes: when a first node of the communication service cluster detects that a WEB front end sends a processing request, a first thread is created and started, or when the first node of the communication service cluster detects that the WEB front end sends the processing request, the first thread is obtained from a thread pool and the obtained first thread is started;
a first node of the communication service cluster starts a first thread and a first communication channel of a first line Cheng Chuangjian;
in this embodiment, the request parameter includes an interface name, a device number, a random number, and a signature result, and determining whether the obtained request parameter is legal includes: judging whether the interface name belongs to the interface name in the preset range, judging whether the format of the equipment number is correct, verifying the signature result according to the interface name, the equipment number and the random number, and judging whether the verification is successful, wherein if the verification is successful, the request parameter is legal, otherwise, the request parameter is illegal;
optionally, the format of the new processing instruction in this step is json format;
preferably, the sending the new processing instruction to the first node of the service cluster according to the second preset rule includes: the first node of the communication service cluster sends a new processing instruction to the first node of the business service cluster according to a second preset rule and in a first preset mode; for example, a first preset mode HTTP Post request mode;
optionally, in this embodiment, after sending the new processing instruction to the first node of the service cluster according to the second preset rule, the method further includes: the first node of the communication service cluster judges whether the new processing instruction is sent successfully or not, if not, the new processing instruction is sent to the first node of the business service cluster again according to a second preset rule, whether the new processing instruction is sent successfully or not is judged, and if not, the interface abnormal information is sent to the WEB front end through a first communication channel;
optionally, the second preset rule in this embodiment may be the same as or different from the first preset rule, and may be any one of a polling method, a random method, a weighted polling method, a weighted random method, a source address hashing method, and a minimum link number method;
when a first node of the communication service cluster receives success information returned by the first node of the business service cluster, correspondingly storing the generated business ID and a first communication channel, and suspending the first communication channel;
specifically, in this embodiment, the storing the generated service ID and the first communication channel correspondingly includes: correspondingly storing the generated service ID and a reference object of a first communication channel in a communication service, and binding the first communication channel of the first thread for overtime monitoring;
if the first node of the communication service cluster monitors that the time is out, closing the first communication channel, and if the WEB front end communicates with the node of the communication service cluster again, the first node of the communication service cluster needs to establish the first communication channel again through a first thread;
in this embodiment, when the first communication channel of the first thread is suspended, the other communication channels of the first thread and the communication channels of the other threads can all receive, process, and send data normally;
when any node of the communication service cluster detects that data exists in the message queue, the data is acquired from the message queue through a broadcast message mode, whether the acquired data needs to be processed or not is judged, if yes, a first communication channel corresponding to a service ID in the acquired data is awakened, the acquired data is sent to a WEB front end through the awakened first communication channel, and if not, the acquired data is discarded;
specifically, in this embodiment, acquiring data from a message queue in a broadcast message mode, and determining whether the acquired data needs to be processed, if so, waking up a first communication channel corresponding to a service ID in the acquired data, and sending the acquired data to a WEB front end through the woken up first communication channel, otherwise, discarding the acquired data, including: acquiring message content from a message body of a message queue in a broadcast message mode, searching a reference object of a first communication channel from communication service according to a service ID in the message content, awakening the first communication channel corresponding to the service ID in the message content if the reference object is found, sending a processing result in the message content to a WEB front end through the awakened first communication channel, and discarding the acquired message content if the reference object is not found;
when a first node of a business service cluster receives a new processing instruction sent by the first node of the communication service cluster, successful information is returned to the first node of the communication service cluster, an interface parameter is obtained from the new processing instruction, the IP of a server where the long connection of equipment corresponding to the equipment number in the interface parameter is located is obtained, a processing message is generated according to the interface name and the business ID in the interface parameter, and the processing message is sent to the first node corresponding to the obtained IP in the equipment service cluster;
optionally, in this embodiment, the obtaining of the interface parameter from the new processing instruction and obtaining of the IP of the server where the long connection of the device corresponding to the device number in the interface parameter is located further includes: judging the service type according to the acquired interface parameters, if the service type is the service which does not need to be sent to the terminal equipment, processing according to the interface parameters, and storing the processing result in a message queue, if the service type is the service which needs to be sent to the terminal equipment, acquiring the IP of a server where the long connection of the equipment corresponding to the equipment number in the interface parameters is located;
optionally, in this embodiment, acquiring an interface parameter from the new processing instruction, acquiring an IP of a server where a long connection of a device corresponding to the device number in the interface parameter is located, and generating a processing packet according to the interface name and the service ID in the interface parameter includes: acquiring interface parameters from the new processing instruction, generating a message ID, acquiring an IP of a server where the long connection of the equipment corresponding to the equipment number in the interface parameters is positioned, and generating a processing message according to the interface name, the service ID and the message ID in the interface parameters;
when a first node of a service cluster receives a new processing instruction every time, a corresponding message ID is generated when the service type is judged to be a service needing to be sent to a terminal device for processing, and the generated message IDs are different every time;
preferably, in this embodiment, the sending the processing packet to the first node corresponding to the obtained IP in the device service cluster specifically includes: sending the processing message to a first node corresponding to the acquired IP in the equipment service cluster in a first preset mode;
specifically, in this embodiment, acquiring an IP of a server where a long connection of a device corresponding to a device number in an interface parameter is located, and generating a processing packet according to an interface name and a service ID in the interface parameter includes: judging whether the state of the corresponding terminal equipment is normal or not according to the equipment number in the interface parameter, if not, storing the equipment abnormal information in the information queue, if so, acquiring the IP of the server where the long connection of the equipment corresponding to the equipment number is positioned, if not, storing the acquired abnormal information in the information queue, and if so, generating a processing message according to the interface name and the service ID in the interface parameter;
wherein, whether the state of the corresponding terminal equipment is normal is judged according to the equipment number in the interface parameter, which comprises the following steps: judging whether the corresponding terminal equipment is initialized or not according to the equipment number, judging whether the corresponding terminal equipment is activated or not according to the equipment number, judging whether the state of the corresponding terminal equipment is unlocked or not according to the equipment number, if so, judging that the state of the corresponding terminal equipment is normal, otherwise, judging that the state of the corresponding terminal equipment is abnormal;
for example, if the service that does not need to be sent to the terminal device is a request for order lookup, the detailed order information is queried according to the order number in the interface parameter, and the found detailed order information is stored in the message queue; if the service needing to be sent to the terminal equipment is equipment information acquisition, acquiring an IP of a server where the long connection of the equipment corresponding to the equipment number is located from a database, generating an equipment information acquisition message according to an interface name and a service ID in the interface parameter and the generated message ID, and sending the equipment information acquisition message to a first node corresponding to the acquired IP in the equipment service cluster;
when a first node of the business service cluster receives a processing result sent by a first node of the equipment service cluster, storing the processing result in a message queue;
specifically, in this embodiment, storing the processing result in the message queue includes:
step T1, a first node of the business service cluster judges whether a client of the message queue needs to be initialized, if so, the client of the message queue is initialized, and step T2 is executed, otherwise, the step T2 is directly executed;
the client for initializing the message queue comprises: a client instance for creating a message queue, setting an IP of the message queue, setting a retry interval time when a message is failed to be sent, setting a sending timeout time, and starting the message queue;
step T2, the first node of the service cluster generates a message body according to the processing result and the service ID and stores the message body in a message queue;
further, step T2 includes: a first node of the service cluster generates message content according to the processing result and the service ID, assembles a message body according to the message content, stores the message body in a message queue, and records a log according to the storage result;
when a first node of the equipment service cluster receives a processing message sent by the first node of the business service cluster, sending the processing message to the long-connection terminal equipment;
optionally, in this embodiment, when the first node of the device service cluster receives the processing packet sent by the first node of the service cluster, sending the processing packet to the long-connection terminal device includes: when a first node of the equipment service cluster receives a processing message sent by the first node of the business service cluster, acquiring an interface name, a message ID and a business ID from the processing message, judging whether the received processing message is processed according to the message ID, if so, reporting an error, otherwise, storing the acquired message ID, and sending the processing message to the long-connection terminal equipment;
optionally, the step of storing the acquired message ID may be replaced by: replacing the stored message ID with the acquired message ID;
further, determining whether the received processing packet is processed according to the message ID includes: judging whether the message ID is consistent with the stored message ID, if so, processing the processed message, otherwise, not processing the processed message;
and when the first node of the equipment service cluster receives the processing result returned by the terminal equipment, sending the processing result to the first node of the business service cluster.
In this embodiment, the nodes of the service cluster store the processing results in the message queue, and each node in the communication service cluster actively acquires data from the message queue in a mode of broadcasting messages and judges whether the data is needed by itself, without storing and maintaining the corresponding relationship between the nodes of the service cluster and the nodes in the communication service cluster when communication is performed, so that the complexity of the distributed cluster system in realizing asynchronous request-to-synchronous conversion is simplified, the dependence between calls of the distributed system is reduced, and decoupling is more thorough and efficient; meanwhile, the development, deployment and maintenance costs are saved, the complexity of service processing and the resource consumption are reduced, and the overall processing efficiency and performance of the system are improved.
EXAMPLE III
A third embodiment of the present invention provides a method for processing a synchronization request response in a distributed cluster system, which is applicable to a system including a WEB front end, a communication service cluster, a service cluster, a message queue, and an equipment service cluster, where the communication service cluster, the service cluster, and the equipment service cluster all include multiple nodes, and a node in communication is a first node, and as shown in fig. 2, the method in this embodiment includes:
step 201: when a WEB front end receives a processing request triggered by a user, sending the processing request to a first node of a communication service cluster through an API (application programming interface) according to a first preset rule;
in this embodiment, after receiving a processing request from a WEB front end, an API selects a corresponding communication service according to a polling method and sends the processing request to a first node of a communication service cluster;
in this embodiment, the communication service cluster includes a plurality of nodes (e.g., A1, A2, A3 …), where the first node is A1;
step 202: when a first node of a communication service cluster detects that a WEB front end sends a processing request through an API, a first thread is started, a first communication channel is established through the first thread, the processing request is received through the first communication channel, and request parameters are obtained from the processing request;
in this embodiment, the request parameters in this step include: first parameter param1: interface name getDeviceInfo, second parameter param2: device number deviceCode, third parameter param3: random number nonce, fourth parameter param4: signature result sign),
obtaining request parameters (e.g., param1: getDeviceInfo, param2: deviceCode, param3: nonce, param4: sign) from the processing request through a first communication Channel (e.g., channel _ 1);
for example, the processing request in this embodiment is: { "method": getDeviceInfo "," deviceCode ": 101210030001", "nonce": fb86fef2-54ca-4013-ba31-c3deb97bc89f "," sign ": rauo0 VptaHWprjrNTAzc 7dJCbYsxI84UiGHrtxZzI =" };
step 203: the first node of the communication service cluster judges whether the acquired request parameter is legal or not, if so, step 204 is executed, otherwise, the interface error information is forwarded to the WEB front end through a first communication channel by an API (application programming interface);
specifically, in this embodiment, the determining whether the request parameter is legal includes: judging whether the interface name belongs to the interface name in the preset range, judging whether the format of the equipment number is correct, verifying the signature result according to the interface name, the equipment number and the random number, and judging whether the verification is successful, wherein if the verification is successful, the request parameter is legal, otherwise, the request parameter is illegal;
wherein, verify the signature result according to interface name, apparatus number, random number, and judge whether to verify successfully, including: splicing the interface name, the equipment number and the random number, signing the splicing result by using a stored symmetric key to obtain a signature value, judging whether the signature value is consistent with the signature result, if so, successfully verifying, and otherwise, failing to verify;
for example, the interface error information forwarded to the WEB front end by the API through the first communication channel is: { "code": 0001"," msg _ desc ": parameter error", "sign": rauo0VpTAHWprNjlrNTAzc7dJCbYsxI84UiGHrtxZzI = "," nonce ": fb86 fef-54 ca-4013-ba31-c3deb97bc89f" }; wherein the interface error information includes: numbering, processing results, signature results, random numbers;
step 204: a first node of the communication service cluster generates a service ID, and a new processing instruction in a json format is formed according to the interface name, the equipment number and the service ID in the request parameter;
for example, the new processing instruction composed in this step is: { "method": getDeviceInfo "," deviceCode ": 101210030001", "requestID": fb86fef2-54ca-4013-ba31-c3deb97bc89f-b978601-c897bc "};
step 205: the first node of the communication service cluster sends the new processing instruction in the json format to the first node of the business service cluster according to a second preset rule and in a first preset mode;
in this embodiment, the second preset rule may be the same as or different from the first preset rule;
for example, the first preset mode is an Http POST request mode; the second preset rule is a minimum link number method, the communication service cluster comprises nodes B1, B2 and B3 … …, the link number of the B2 is minimum, and the node A1 of the communication service cluster sends a json-format new processing instruction to the node B2 of the business service cluster in an Http POST request mode according to the minimum link number method;
optionally, in this embodiment, after step 205, the method further includes: the first node of the communication service cluster judges whether the new processing instruction is sent successfully or not, if so, the step 206 is executed, otherwise, the new processing instruction is sent to the first node of the service cluster again according to a second preset rule and through a first preset mode, and whether the new processing instruction is sent successfully or not is judged, if so, the step 206 is executed, otherwise, the interface abnormal information is forwarded to the WEB front end through a first communication channel by an API;
for example, the interface exception information returned by the API to the WEB front end through the first communication channel is: { "code": 0002"," msg _ desc ": service processing failure", "sign": rauo0 vptahwprnjlnntnazc 7 djjcbysxi 84UiGHrtxZzI = "," nonce ": fb86fef2-54ca-4013-ba31-c3deb97bc89f" };
step 206: the first node of the business service cluster receives a new processing instruction, acquires the interface parameters from the new processing instruction and returns success information to the first node of the communication service cluster;
in this embodiment, the interface parameters include: interface name, equipment number, service ID;
for example, the success information in this step is: { "code": 0000), "msg _ desc": success "," requestID ": fb86fef2-54ca-4013-ba31-c3deb97bc89f-b978601-c897bc" }; wherein the success information includes: numbering, processing result and service ID;
step 207: when the first node of the communication service cluster receives success information returned by the first node of the service cluster, the service ID and a first communication channel of the first thread are correspondingly added into a storage container, and the first communication channel of the first thread is suspended;
in this embodiment, when the first communication channel of the first thread is suspended, the other communication channels of the first thread and the communication channels of the other threads can both normally receive, process, and send data;
specifically, in this embodiment, after receiving the success information, the first node of the communication service cluster correspondingly stores the service ID and the reference object of the first communication channel of the first thread in the communication service, and monitors when the first communication channel of the first thread is bound up;
for example, the service ID is stored in correspondence with the reference object of the first communication Channel of the first thread in ConcurrentMap < String, channel > (tcpChannelMap); if the first node of the communication service cluster monitors timeout (i.e. success information is not received within the preset time), the first communication channel of the first thread is closed, and subsequently, if the WEB front end communicates with the first node of the communication service cluster again, the first node of the communication service cluster needs to reestablish the first communication channel through the first thread;
step 208: the first node of the service cluster judges the service type according to the interface name in the interface parameter, if the service is not required to be sent to the terminal device, step 209 is executed, and if the service is required to be sent to the terminal device, step 210 is executed;
in this embodiment, a first node of a service cluster determines an interface name in an interface parameter, where the service type is a service that does not need to be sent to a terminal device if the interface name is getOrderinfo (query order information), and the service type is a service that needs to be sent to the terminal device if the interface name is getDeviceInfo (obtain device information);
step 209: the first node of the service cluster processes according to the interface parameter, and stores the processing result in the message queue, and executes step 217;
optionally, in this embodiment, step 209 specifically includes: the first node of the business service cluster inquires the order information, and stores the inquiry result in the message queue, and executes step 217;
in this embodiment, the query result includes a number, a processing result, a service ID, and an order basic information table;
for example, the query result sent to the message queue in this step is: { "code": 0000), "msg _ desc": success "," requestID ": fb86fef2-54ca-4013-ba31-c3deb97bc89f-b978601-c897bc", "orderInfo": xxxxx "};
step 210: a first node of the service cluster generates a message ID, judges whether the state of the corresponding terminal device is normal according to the device number in the interface parameter, if so, executes step 211, otherwise, stores the device abnormal message in a message queue, and executes step 217;
specifically, in this embodiment, determining whether the state of the corresponding terminal device is normal according to the device number in the interface parameter includes: judging whether the corresponding terminal equipment is initialized according to the equipment number in the interface parameter, judging whether the corresponding terminal equipment is activated according to the equipment number, judging whether the state of the corresponding terminal equipment is unlocked according to the equipment number, if so, judging that the state of the corresponding terminal equipment is normal, otherwise, judging that the state of the corresponding terminal equipment is abnormal;
in this embodiment, the device exception message in this step includes a number, a processing result, and a service ID;
for example, the device exception message generated in this step is: { "code": 0001"," msg _ desc ": processing failure, device not initialized/device not activated/device locked", "requestID": fb86fef2-54ca-4013-ba31-c3deb97bc89f-b978601-c897bc "};
step 211: a first node of the business service cluster acquires the IP of a server where the long connection of the equipment corresponding to the equipment number is positioned from a database, if the IP is acquired, step 212 is executed, if the IP is not acquired, the acquired abnormal message is stored in a message queue, and step 217 is executed;
specifically, the step of storing the acquired exception message in a message queue includes:
a1, a first node of a business service cluster judges whether a client of a message queue needs to be initialized, if so, the client of the message queue is initialized, and A2 is executed, otherwise, the step A2 is directly executed;
in this embodiment, the client that initializes the message queue specifically includes: a client instance that creates a message queue, sets the IP (i.e., port address) of the message queue, sets a retry interval when sending a message fails, sets a send timeout time, starts the message queue;
step A2, a first node of the business service cluster generates a message body according to the acquired abnormal information and the business ID and stores the message body in a message queue;
specifically, step A2 includes: a first node of the service cluster generates message content according to the acquired abnormal information and the service ID, assembles a message body according to the message content, stores the message body in a message queue, and records a log according to a storage result;
for example, the IP of the server in this step is 192.168.1.1, and the acquired exception information in this step is: the processing fails, and the equipment is not on-line;
the message content is as follows: string body = "{" code ": 0002", "msg _ desc": failure of processing, off-line of equipment "," requestID ": fb86fef2-54ca-4013-ba31-c3deb97bc89f-b978601-c897bc" } ";
the message body is assembled according to the message content as follows: { "topoic": deviceInfo "," tag ": and" "body": and "{" code ": 0002", "msg _ desc": and "failure of treatment, off-line in the apparatus", "requestID": and "fb86 fef-54 ca-4013-ba31-c3deb97bc89f-b978601-c897bc" } ";
the preservation process comprises the following steps: { "sendStatus": SEND _0K "," msgId ": C0A8018A15E818B4AAC2549D90420000", "offsetMsgId": C0A8016B0002A9F000000001633EE9"," topic ": deviceInfo", "brookerame": brush-a "," queueId ": 9", "queueOffset": 0"};
the message body is stored in a message queue (rockmq) as: sendResult = this.producer.send (message, 10000L);
if the sending is successful, the recorded log is SEND _ OK, and if the sending is failed, the recorded log is SLAVE _ NOT _ AVAILABLE;
step 212: a first node of the service cluster generates a processing message according to the interface name, the message ID and the service ID, and sends the processing message to a first node corresponding to the acquired IP in the equipment service cluster in an HTTP Post request mode;
for example, the processing packet generated in this step is: { "at": getDeviceInfo "," msg _ id ":"11111111"," requestID "," fb86fef2-54ca-4013-ba31-c3deb97bc89f-b978601-c897bc "}; the node B2 of the service cluster sends the processing message to a node C3 in the equipment service cluster in an HTTP Post request mode;
in this embodiment, the device service cluster is a service cluster that maintains long connection with the terminal device, the terminal device sends a connection establishment request to a node of the device service cluster after starting up, and the node in the device service cluster binds with the terminal device when receiving the connection establishment request (that is, the device number of the terminal device and the node IP used for connection are correspondingly stored in a database (e.g., redis), and the device number and the long connection reference are placed in an element storage memory (e.g., hashMap);
in this embodiment, the database is a high-performance key-value pair database, and nodes of all clusters can be accessed;
step 213: when receiving the processing message, the first node of the equipment service cluster acquires a message ID number and a service ID from the processing message and sends the processing message to the long-connection terminal equipment;
optionally, in this embodiment, before sending the processing packet to the long-connection terminal device in step 213, the method further includes: the first node of the equipment service cluster judges whether the received processing message is processed or not according to the message ID, if so, the first node of the service cluster returns error information, otherwise, the processing message is sent to the terminal equipment with long connection;
the method includes that a first node of an equipment service cluster judges whether a received processing message is processed according to a message ID, and specifically includes: the first node of the equipment service cluster judges whether the acquired message ID is consistent with the stored message ID, if so, the received processing message is processed, and returns error information to the first node of the service cluster, otherwise, the stored message ID is updated by the acquired message ID, and the processing message is sent to the long-connection terminal equipment;
in this embodiment, the terminal device establishes a long connection with a node in the device service cluster according to the device number and performs communication;
the nodes of the equipment service cluster can be in long connection with different terminal equipment and can interact with the terminal equipment in real time so as to process services of various terminal equipment, such as equipment message pushing, equipment local log acquisition, equipment position acquisition, equipment electric quantity acquisition and equipment remote restarting;
step 214: the terminal equipment receives the processing message and then carries out corresponding processing, and returns a processing result to the first node of the equipment service cluster;
for example: the interface name in this embodiment is to obtain device information, and the returned processing result includes terminal device information and a service ID;
the processing message received by the terminal equipment is as follows: { "at": getDeviceInfo "," msg _ id ":"11111111"," requestID "," fb86fef2-54ca-4013-ba31-c3deb97bc89f-b978601-c897bc "};
the processing result returned by the terminal device to the first node of the device service cluster is: { "version": 1011"," device _ info ": sdk _ version": 1001"," wifi _ version ": 1001", "imei": 222XX "," imsi ": 33XX", "iccid": "}," requestID ": fb86fef2-54ca-4013-ba31-c3deb97bc89f-b978601-c897bc" };
in this embodiment, step 214 includes: the terminal equipment analyzes the received processing message to obtain an interface name, a message ID and a service ID, judges the operation to be carried out according to the interface name, if the operation is to acquire equipment information, the terminal equipment searches equipment information stored in the terminal equipment, generates a processing result according to the found equipment information and the service ID and returns the processing result to the first node of the equipment service cluster;
step 215: a first node of the equipment service cluster receives a processing result returned by the terminal equipment and sends the processing result to a first node of the business service cluster;
step 216: after receiving the processing result, the first node of the business service cluster stores the processing result in a message queue;
specifically, in this embodiment, the data stored in the message queue may be a processing result, a query result, an equipment exception message, or an acquired exception message;
in this embodiment, the manner of acquiring data in the message queue includes: a cluster mode and a mode of broadcasting messages;
the cluster mode is that each consumer in the same consumer group only acquires a part of data, and the messages acquired by all consumers are added to form complete data;
the mode of the broadcast message is that each consumer in the same consumer group obtains complete data;
specifically, the step of storing the processing result in the message queue by the first node of the service cluster includes:
step T1, a first node of the business service cluster judges whether a client of the message queue needs to be initialized, if so, the client of the message queue is initialized, and step T2 is executed, otherwise, the step T2 is directly executed;
in this embodiment, the client that initializes the message queue specifically includes: a client instance that creates a message queue, sets the IP (i.e., port address) of the message queue, sets a retry interval when sending a message fails, sets a send timeout time, starts the message queue;
step T2, the first node of the service cluster generates a message body according to the processing result and the service ID and stores the message body in a message queue;
specifically, in this step, the first node of the service cluster generates message content according to the processing result and the service ID, assembles a message body according to the message content, stores the message body in the message queue, and records a log according to the storage result;
step 217: when any node of the communication service cluster detects that data exists in the message queue, the data is acquired from the message queue through a mode of broadcast messages, whether the acquired data needs to be processed or not is judged, if yes, a first communication channel corresponding to a service ID in the acquired data is awakened, the acquired data is forwarded to a WEB front end through the first communication channel by an API, and if not, the acquired data is discarded;
specifically, in this embodiment, each node in the communication service cluster may obtain data in the message queue using a mode of the broadcast message, initialize a message queue consumption group when the node in the communication service cluster is started, and set a mode of obtaining the data as a mode of the broadcast message;
in this embodiment, step 217 specifically includes: each node of the communication service cluster acquires message content from a message body of a message queue through a mode of broadcasting messages, searches a reference object of a first communication channel from the communication service according to a service ID in the message content, forwards a processing result in the message content to a WEB front end through the first communication channel by an API if the reference object is found, and prompts the current node that the acquired message content does not need to be processed if the reference object is not found, and discards the acquired message content; only nodes of one communication service cluster may find the reference object of the first communication channel in step 217;
for example, the message content obtained in this step is: { "code": 0002"," msg _ desc ": processing failure, apparatus off-line", "requestID": fb86fef2-54ca-4013-ba31-c3deb97bc89f-b978601-c897bc "};
correspondingly, the processing result returned to the WEB front end through the API is: { "code": 0003"," msg _ desc ": device off-line", "sign": rauo0 vptahwprnjlnntnazc 7 djjcbysxi 84UiGHrtxZzI = "," nonce ": fb86fef2-54ca-4013-ba31-c3deb97bc89f" };
step 218: and the WEB front end receives the processing result through the API.
In this embodiment, the WEB front end receives, through the API, a processing result sent by a first node of the communication service cluster;
optionally, in this embodiment, after receiving the processing result according to the API, the WEB front end further includes: and (4) performing page prompting on the user according to the processing result, for example, in the API receiving result, if the code is 0003 and the msg \udesc indicates that the equipment is not online, displaying 'processing failure and equipment is not online' on a WEB front-end interface to prompt the user.
Optionally, an embodiment of the present application further provides an electronic device, where the electronic device includes at least one processor, a memory, and instructions stored on the memory and executable by the at least one processor, and the at least one processor executes the instructions to implement the method for processing a synchronization request response by a distributed cluster system in the foregoing embodiments. When the electronic device is a chip system, the electronic device may be composed of a chip, and may also include a chip and other discrete devices, which is not specifically limited in this embodiment of the present application; the chip is coupled to the memory and configured to execute the computer program stored in the memory to perform the method for processing the synchronization request response by the distributed cluster system disclosed in the foregoing embodiments. The electronic device may be a WEB front end or a communication service cluster or a business service cluster or an equipment service cluster in a distributed cluster system.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented using a software program, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs. The procedures or functions described in accordance with the embodiments of the present application are generated in whole or in part when the computer program is loaded and executed on an electronic device. The computer program may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions may be transmitted from one base station, electronic device, server, or data center to another base station, electronic device, server, or data center by wire (e.g., coaxial cable, fiber optic, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by an electronic device or can comprise one or more available media integrated servers, data centers, and the like. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), among others.
While the present application has been described in connection with various embodiments, other variations to the disclosed embodiments can be understood and effected by those skilled in the art in practicing the claimed application, from a review of the drawings, the disclosure, and the appended claims. In the claims, the word "comprising" does not exclude other elements or steps, and the word "a" or "an" does not exclude a plurality. A single processor or other unit may fulfill the functions of several items recited in the claims. The mere fact that certain measures are recited in mutually different dependent claims does not indicate that a combination of these measures cannot be used to advantage.
Although the present application has been described in conjunction with specific features and embodiments thereof, it will be evident that various modifications and combinations may be made thereto without departing from the spirit and scope of the application. Accordingly, the specification and figures are merely exemplary of the present application as defined in the appended claims and are intended to cover any and all modifications, variations, combinations, or equivalents within the scope of the present application. It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (19)

1. A method for processing synchronous request response by a distributed cluster system is characterized by being applicable to a system comprising a WEB front end, a communication service cluster, a message queue, a business service cluster and an equipment service cluster, wherein the communication service cluster, the business service cluster and the equipment service cluster respectively comprise a plurality of nodes, and a node which is communicating is a first node, and the method comprises the following steps:
when the WEB front end receives a processing request triggered by a user, sending the processing request to a first node of the communication service cluster according to a first preset rule;
when the first node of the communication service cluster detects that the processing request is sent by the WEB front end, starting a first thread, receiving the processing request through the first communication channel of Cheng Chuangjian by the first line, judging whether a request parameter in the processing request is legal or not, if not, sending interface error information to the WEB front end through the first communication channel, if so, forming a new processing instruction according to an interface name and equipment number in the request parameter and the generated service ID, and sending the new processing instruction to the first node of the service cluster according to a second preset rule;
when the first node of the communication service cluster receives success information returned by the first node of the business service cluster, correspondingly storing the generated business ID and the first communication channel, and suspending the first communication channel;
when any node of the communication service cluster detects that data exists in the message queue, acquiring the data from the message queue through a mode of broadcasting messages, judging whether the acquired data needs to be processed, if so, waking up a first communication channel corresponding to a service ID in the acquired data, and sending the acquired data to the WEB front end through the woken up first communication channel, otherwise, discarding the acquired data;
when the first node of the business service cluster receives the new processing instruction sent by the first node of the communication service cluster, successful information is returned to the first node of the communication service cluster, interface parameters are obtained from the new processing instruction, the IP of a server where the long connection of the equipment corresponding to the equipment number in the interface parameters is located is obtained, a processing message is generated according to the interface name and the business ID in the interface parameters, and the processing message is sent to the first node corresponding to the obtained IP in the equipment service cluster;
when the first node of the business service cluster receives a processing result sent by the first node of the equipment service cluster, storing the processing result in the message queue;
when the first node of the equipment service cluster receives a processing message sent by the first node of the business service cluster, sending the processing message to a long-connection terminal device;
and when the first node of the equipment service cluster receives the processing result returned by the terminal equipment, sending the processing result to the first node of the business service cluster.
2. The method of claim 1, wherein said sending the new processing instruction to the first node of the business service cluster according to the second preset rule further comprises: and the first node of the communication service cluster judges whether a new processing instruction is successfully sent or not, if not, the new processing instruction is sent to the first node of the business service cluster again according to the second preset rule, whether the new processing instruction is successfully sent or not is judged, and if not, interface abnormal information is sent to the WEB front end through the first communication channel.
3. The method of claim 1, wherein the sending the new processing instruction to the first node of the business service cluster according to the second preset rule comprises: and the first node of the communication service cluster sends the new processing instruction to the first node of the business service cluster according to a second preset rule and in a first preset mode.
4. The method of claim 1, wherein the starting the first thread when the first node of the communication service cluster detects that the WEB front end transmits the processing request comprises:
when the first node of the communication service cluster detects that the WEB front end sends the processing request, a first thread is created and started, or
And when the first node of the communication service cluster detects that the processing request is sent by the WEB front end, acquiring a first thread from a thread pool and starting the acquired first thread.
5. The method of claim 1, wherein the request parameters include an interface name, a device number, a random number, and a signature result, and the determining whether the acquired request parameters are legitimate comprises: judging whether the interface name belongs to interface names in a preset range, judging whether the format of the equipment number is correct, verifying the signature result according to the interface name, the equipment number and the random number, and judging whether the verification is successful, wherein if the verification is successful, the request parameter is legal, otherwise, the request parameter is illegal.
6. The method of claim 1, wherein said storing said generated service ID in correspondence with said first communication channel comprises: correspondingly storing the generated service ID and the reference object of the first communication channel in a communication service, and binding the first communication channel of the first thread for timeout monitoring;
if the first node of the communication service cluster closes the first communication channel after monitoring timeout, and if the WEB front end communicates with the first node of the communication service cluster again, the first node of the communication service cluster needs to reestablish the first communication channel through the first thread.
7. The method of claim 1, wherein the obtaining the interface parameter from the new processing instruction and obtaining the IP of the server where the long connection of the device corresponding to the device number in the interface parameter is located further comprises: and judging the service type according to the acquired interface parameters, if the service type is the service which does not need to be sent to the terminal equipment, processing according to the interface parameters, storing the processing result in the message queue, and if the service type is the service which needs to be sent to the terminal equipment, acquiring the IP of the server where the long connection of the equipment corresponding to the equipment number in the interface parameters is located.
8. The method of claim 1, wherein the obtaining the IP of the server where the long connection of the device corresponding to the device number in the interface parameter is located, and generating the processing packet according to the interface name and the service ID in the interface parameter comprises: and judging whether the state of the corresponding terminal equipment is normal or not according to the equipment number in the interface parameter, if not, storing an equipment abnormal message in the message queue, if so, acquiring the IP of a server where the long connection of the equipment corresponding to the equipment number is positioned, if not, storing the acquired abnormal message in the message queue, and if so, generating a processing message according to the interface name and the service ID in the interface parameter.
9. The method of claim 8, wherein the determining whether the state of the corresponding terminal device is normal according to the device number in the interface parameter comprises: judging whether the corresponding terminal equipment is initialized or not according to the equipment number, judging whether the corresponding terminal equipment is activated or not according to the equipment number, judging whether the state of the corresponding terminal equipment is unlocked or not according to the equipment number, if so, judging that the state of the corresponding terminal equipment is normal, otherwise, judging that the state of the corresponding terminal equipment is abnormal.
10. The method according to claim 1, wherein the acquiring data from the message queue in a broadcast message mode, and determining whether the acquired data needs to be processed, if yes, waking up a first communication channel corresponding to a service ID in the acquired data, and sending the acquired data to the WEB front end through the woken up first communication channel, otherwise, discarding the acquired data, includes: and acquiring message content from a message body of the message queue in a broadcast message mode, searching a reference object of a first communication channel from a communication service according to a service ID in the message content, if the reference object is found, waking up the first communication channel corresponding to the service ID in the message content, and sending a processing result in the message content to the WEB front end through the woken-up first communication channel, and if the reference object is not found, discarding the acquired message content.
11. The method of claim 1, wherein said storing the processing result in the message queue comprises:
step T1, the first node of the business service cluster judges whether the client of the message queue needs to be initialized, if so, the client of the message queue is initialized, and step T2 is executed, otherwise, the step T2 is directly executed;
and step T2, the first node of the business service cluster generates a message body according to the processing result and the business ID and stores the message body in the message queue.
12. The method of claim 11, wherein the client initializing a message queue comprises: a client instance that creates a message queue, sets the IP of the message queue, sets the retry interval time when sending a message fails, sets the send timeout time, and starts the message queue.
13. The method of claim 11, wherein the step T2 comprises: and the first node of the business service cluster generates message content according to the processing result and the business ID, assembles a message body according to the message content, stores the message body in the message queue and records a log according to the storage result.
14. The method according to claim 1, wherein the obtaining of the interface parameter from the new processing instruction, obtaining an IP of a server in which a long connection of a device corresponding to the device number in the interface parameter is located, and generating the processing packet according to the interface name and the service ID in the interface parameter comprises: acquiring interface parameters from the new processing instruction, generating a message ID, acquiring an IP of a server where a long connection of equipment corresponding to the equipment number in the interface parameters is located, and generating a processing message according to the interface name and the service ID in the interface parameters and the message ID;
when the first node of the device service cluster receives the processing message sent by the first node of the service cluster, the sending of the processing message to the long-connection terminal device includes: when the first node of the equipment service cluster receives a processing message sent by the first node of the business service cluster, acquiring an interface name, a message ID and a business ID from the processing message, judging whether the received processing message is processed according to the message ID, if so, reporting an error, otherwise, storing the message ID, and sending the processing message to a long-connection terminal device.
15. The method of claim 14, wherein said determining whether the received processed packet was processed based on the message ID comprises: and judging whether the message ID is consistent with the stored message ID, if so, processing the processed message, otherwise, not processing the processed message.
16. A distributed cluster system, comprising: the system comprises a WEB front end, a communication service cluster, a message queue, a business service cluster and an equipment service cluster, wherein the communication service cluster, the business service cluster and the equipment service cluster all comprise a plurality of nodes, and the node which is communicating is a first node;
the WEB front end is used for sending a processing request to a first node of the communication service cluster according to a first preset rule when receiving the processing request triggered by a user;
the first node of the communication service cluster is used for starting a first thread when detecting that the processing request is sent by the WEB front end, receiving the processing request through the first communication channel by the first thread Cheng Chuangjian, judging whether a request parameter in the processing request is legal or not, if not, sending interface error information to the WEB front end through the first communication channel, if so, forming a new processing instruction according to an interface name and equipment number in the request parameter and the generated service ID, and sending the new processing instruction to the first node of the service cluster according to a second preset rule;
the first node of the communication service cluster is further configured to, when receiving success information returned by the first node of the service cluster, correspondingly store the generated service ID and the first communication channel, and suspend the first communication channel;
any node of the communication service cluster is further used for acquiring data from the message queue in a broadcast message mode when detecting that the message queue contains the data, judging whether the acquired data needs to be processed or not, if so, waking up a first communication channel corresponding to a service ID in the acquired data, and sending the acquired data to the WEB front end through the woken up first communication channel, otherwise, discarding the acquired data;
the first node of the business service cluster is used for returning success information to the first node of the communication service cluster when receiving the new processing instruction sent by the first node of the communication service cluster, acquiring an interface parameter from the new processing instruction, acquiring an IP of a server where a long connection of a device corresponding to the device number in the interface parameter is located, generating a processing message according to the interface name and the business ID in the interface parameter, and sending the processing message to the first node corresponding to the acquired IP in the device service cluster;
the first node of the business service cluster is further used for storing a processing result in the message queue when receiving the processing result sent by the first node of the equipment service cluster;
the message queue is used for storing data sent by the nodes of the business service cluster;
the first node of the equipment service cluster is used for sending the processing message to the long-connection terminal equipment when receiving the processing message sent by the first node of the business service cluster;
and the first node of the equipment service cluster is also used for sending the processing result to the first node of the business service cluster when receiving the processing result returned by the terminal equipment.
17. An electronic device comprising at least one processor, memory, and instructions stored on the memory and executable by the at least one processor, the at least one processor executing the instructions to implement the method of processing synchronization request responses by the distributed cluster system of any of claims 1 to 15.
18. A computer readable storage medium, characterized in that the computer readable storage medium comprises a computer program which, when run on an electronic device, causes the electronic device to perform the method of a distributed cluster system of any of claims 1 to 15 to process a synchronization request response.
19. A chip system, comprising a chip coupled to a memory for executing a computer program stored in the memory to perform the method of processing synchronization request responses by the distributed cluster system of any of claims 1 to 15.
CN202211250376.9A 2022-10-13 2022-10-13 Distributed cluster system and method for processing synchronous request response Active CN115334066B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211250376.9A CN115334066B (en) 2022-10-13 2022-10-13 Distributed cluster system and method for processing synchronous request response

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211250376.9A CN115334066B (en) 2022-10-13 2022-10-13 Distributed cluster system and method for processing synchronous request response

Publications (2)

Publication Number Publication Date
CN115334066A true CN115334066A (en) 2022-11-11
CN115334066B CN115334066B (en) 2023-02-24

Family

ID=83913403

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211250376.9A Active CN115334066B (en) 2022-10-13 2022-10-13 Distributed cluster system and method for processing synchronous request response

Country Status (1)

Country Link
CN (1) CN115334066B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050125508A1 (en) * 2003-12-04 2005-06-09 Smith Kevin B. Systems and methods that employ correlated synchronous-on-asynchronous processing
US20070150598A1 (en) * 2002-05-02 2007-06-28 Bea Systems, Inc. System and method for providing highly available processing of asynchronous service requests
US20090210876A1 (en) * 2008-02-20 2009-08-20 Jinmei Shen Pull-model Workload Management with Synchronous-Asynchronous-Synchronous Bridge
CN109150988A (en) * 2018-07-27 2019-01-04 上海盛付通电子支付服务有限公司 A kind of request processing method and its server
US20190311054A1 (en) * 2018-04-10 2019-10-10 Walmart Apollo, Llc High throughput order fullfillment database system
CN112118266A (en) * 2020-09-24 2020-12-22 焦点科技股份有限公司 Distributed state synchronization method based on cooperation of HTTP and WebSocket
CN113946427A (en) * 2021-10-29 2022-01-18 中国建设银行股份有限公司 Task processing method, processor and storage medium for multi-operating system

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070150598A1 (en) * 2002-05-02 2007-06-28 Bea Systems, Inc. System and method for providing highly available processing of asynchronous service requests
US20050125508A1 (en) * 2003-12-04 2005-06-09 Smith Kevin B. Systems and methods that employ correlated synchronous-on-asynchronous processing
US20090210876A1 (en) * 2008-02-20 2009-08-20 Jinmei Shen Pull-model Workload Management with Synchronous-Asynchronous-Synchronous Bridge
US20190311054A1 (en) * 2018-04-10 2019-10-10 Walmart Apollo, Llc High throughput order fullfillment database system
CN109150988A (en) * 2018-07-27 2019-01-04 上海盛付通电子支付服务有限公司 A kind of request processing method and its server
CN112118266A (en) * 2020-09-24 2020-12-22 焦点科技股份有限公司 Distributed state synchronization method based on cooperation of HTTP and WebSocket
CN113946427A (en) * 2021-10-29 2022-01-18 中国建设银行股份有限公司 Task processing method, processor and storage medium for multi-operating system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
杨海涛等: ""大规模云同步归集数据系统的异步并行优化"", 《计算机工程与应用》 *

Also Published As

Publication number Publication date
CN115334066B (en) 2023-02-24

Similar Documents

Publication Publication Date Title
US8166163B2 (en) Server checking using health probe chaining
EP3734913A1 (en) Communication method and communication apparatus
US20120297059A1 (en) Automated creation of monitoring configuration templates for cloud server images
CN110505275A (en) Data transmission method, system, server and computer readable storage medium
CN104144098A (en) Information pushing method and system and pushing server equipment
US10917289B2 (en) Handling network failures in networks with redundant servers
WO2011026430A1 (en) Method and system for data synchronization in content delivery network
WO2014169804A1 (en) Registration method and system for common service entity
CN108055157B (en) Service node acquisition method and device
CN107864143B (en) Self-evolution efficient proxy resource supply system and method
CN110098987B (en) Method for balancing multilayer long connection load of Internet of things
CN108134713B (en) Communication method and device
CN103907373A (en) Systems and methods for network quality estimation, connectivity detection, and load management
CN114338063B (en) Message queue system, service processing method and computer readable storage medium
CN103891252A (en) Systems and methods for network quality estimation, connectivity detection, and load management
CN104348661B (en) The upload of network failure data, method of reseptance and equipment and recording method and system
CN102801825B (en) Terminal multiple IP (Internet Protocol) address validity detection method
CN111343286A (en) Network access system and network access method
US10680930B2 (en) Method and apparatus for communication in virtual network
CN107707939B (en) Video access method, access balance server, central server and system
CN115334066B (en) Distributed cluster system and method for processing synchronous request response
CN111225080B (en) Method for acquiring gateway down-hanging equipment information
WO2014015525A1 (en) Method and device for querying for user online state
CN101632261B (en) Full mesh rates transaction in a network
CN113794620B (en) Message sending method, device, equipment, system and 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
GR01 Patent grant
GR01 Patent grant