Message sequence control method under distributed architecture
By allocating fixed services to each user in the cloud and using Kafka queue and hash algorithm to process messages, the problem of out-of-order messages under the distributed architecture is solved, and the efficiency of message processing and business control is achieved, ensuring intelligence Timeliness and efficiency of home equipment.
Patent Information
- Application Number
- CN202310663678.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-06
- Publication Date
- 2024-12-06
AI Technical Summary
Under a distributed architecture, messages may cause out-of-order messages during message processing, resulting in problems such as disordered business control.
By assigning fixed services to each user in the cloud and assigning messages to the corresponding service in queue order, using Kafka queue and hash algorithm for message allocation and processing, setting time thresholds to determine the validity of messages, and passing through the gateway Perform queue storage and priority management of instruction information.
Ensure that messages from the same user are processed in chronological order, avoid timing disorders caused by messages being distributed to different services, improve the orderliness and efficiency of business control, and ensure the timeliness and efficiency of smart home devices.
Smart Images

Figure CN119094615A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a message sequence control method under a distributed architecture, and belongs to the technical field of information processing. Background Art
[0002] Through the mobile application APP, some services or data are requested from the backend service, such as user login, registration, data acquisition, etc. In order to prevent the processing capacity of one service from being insufficient, a distributed service is required.
[0003] The cloud service is distributed in multiple nodes, but the messages executed by the device are sequential. For example, a registered user enters the homepage after registration and obtains data. The first request is to register and the second request is to obtain the data list. Normally, registration is required first, and then data is obtained. Figure 1 As shown, according to the conventional message processing method, the first request and the second request may be assigned to different services for processing, and the time taken by different services for processing may be different. Therefore, the second request may be processed and sent out first, and the first request may be processed later, which will cause the device to receive the second request first and then the first request, resulting in a disorderly order and causing chaos to the business. Summary of the invention
[0004] The purpose of the present invention is to provide a message sequence control method under a distributed architecture to solve the problem of business control disorder caused by the inability to process messages in sequence in the control process under the current distributed architecture.
[0005] In order to solve the above technical problems, the present invention provides a message sequence control method under a distributed architecture, the method comprising the following steps:
[0006] 1) Allocate services to each user in the cloud, and users and services are relatively fixed;
[0007] 2) After receiving the messages sent by the user, the cloud arranges them in queue order and assigns the messages to the service corresponding to the user, so that the messages sent by the same user are processed by the same service;
[0008] 3) Each service processes the received message, obtains the corresponding instruction information, and sends the instruction information to the corresponding device.
[0009] The present invention allocates services to each user in the cloud, making the users and services relatively fixed. In this way, after receiving the message sent by the user, the cloud will allocate the message to the service corresponding to the user, so that the messages sent by the same user are processed by the same service, and each service processes the received message, obtains the corresponding instruction information, and sends the instruction information to the corresponding device. Through this control method, the messages of the same user will reach a service in time sequence, and the service will process them in order, avoiding the problem of time disorder caused by the same user's messages being assigned to different services for processing.
[0010] Furthermore, in step 3), each service needs to perform a time comparison after receiving the message. If the difference between the time the service receives the message and the time the user sends the message exceeds a set threshold, the message is considered invalid, the service will no longer process the message, and will re-request the corresponding user.
[0011] The present invention is also provided with time control, which determines whether the message is valid by the time difference between the time when the service receives the message and the time when the user sends the message, thereby avoiding the message from being invalid due to too long a time, and ensuring the high efficiency of the control.
[0012] Furthermore, each service sends the instruction information to the corresponding device through the gateway.
[0013] Furthermore, after receiving the instruction information, the gateway divides the instruction information into queues and stores it according to its type, with the same type of instruction information being in one queue and different types of instructions being in different queues.
[0014] The present invention stores instruction information received at the gateway side in queues according to the type of instruction information. The same type of instruction information is in one queue, and different types of instructions are in different queues, so that different types of instructions can be stored and managed separately.
[0015] Furthermore, the queue includes a first queue for storing single control instructions, a second queue for storing scene instructions, and a third queue for storing instructions issued by the system.
[0016] Furthermore, the priorities of the first queue, the second queue and the third queue decrease in sequence.
[0017] The present invention sets the priority of the first queue to be higher than that of the second queue, so that single control instructions are processed first, and the priority of the third queue is the lowest, which prioritizes the timeliness of the control of smart home devices.
[0018] Furthermore, in step 1), a hash algorithm is used to allocate services to each user.
[0019] Furthermore, the step 2) is controlled by using a Kafka queue. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 It is a schematic diagram of a message sequence control method under a distributed architecture in the prior art;
[0021] Figure 2 It is a schematic diagram of a message sequence control method under a distributed architecture in an embodiment of the present invention. DETAILED DESCRIPTION
[0022] The specific implementation of the present invention will be further described below in conjunction with the accompanying drawings.
[0023] The present invention allocates services to each user in the cloud, so that users and services are relatively fixed; after receiving messages sent by users, the cloud arranges them in queue order and allocates the messages to the services corresponding to the users; each service processes the received messages, obtains corresponding instruction information, and sends the instruction information to the corresponding devices. The following is an example of the application scenario of smart home.
[0024] In the application scenario of smart home, the user controls the smart furniture equipment through the mobile phone APP. For example, when the user needs to control the lights in the room to turn off through the mobile phone APP, the user uses the mobile phone APP to send the corresponding message to the cloud. The cloud processes the received message through the home service module set up, converts it into the corresponding control instruction (turn off the light) and sends it to the corresponding furniture equipment (such as the light) through the gateway device, thereby realizing the control of turning off the light through the mobile phone APP. Considering the current development of smart home control, the needs of users are also increasing. For this reason, the cloud is equipped with multiple distributed home services. The cloud distributes the received messages sent by users to each home service to achieve efficient control.
[0025] On this basis, for multiple distributed home services in the cloud, the present invention allocates users and home services according to a set algorithm, so that users and home services form a pairing relationship, that is, each user is assigned a fixed home service. For example, the user can be uniquely numbered. For example, there are n users in total, numbered 1, 2, ... n, and the number is modulo the number of home services m, and 1 is modulo n. For example, the remainder of 1 divided by n is 1, so the request numbered 1 is handed over to home service 1 for processing. Similarly, the allocation of all users can be achieved, so that each user is assigned a corresponding home service. As other implementation methods, other allocation methods, such as hash functions, etc., can also be used. By allocating a fixed home service to each user, when the cloud receives a request message sent by a user, the request message sent by the same user will reach the same home service.
[0026] When the cloud receives the request message sent by the user, it arranges it in the Kafka queue in the order in which it is received, and sends each request message to the corresponding home service in that order. In this way, the request messages of the same user at different times can arrive at the same corresponding home service in chronological order, and the home service can process the request messages of the same user in chronological order, which can avoid the problem of the same user's request messages being assigned to different home services for processing, and the problem of business control disorder caused by the delay caused by different home services processing, which causes the request messages sent later by the same user to be processed and sent out first.
[0027] For example, if there are 2 users at home, Figure 2 As shown, each user needs to control the light through the app. Two users send a request message for controlling the light to the cloud through the app. If the initial state of the light is on, both users are ready to turn off the light at 9:50. User 1 sends a shutdown request instruction through APP1, and the cloud assigns it to service (1). After service (1) processes it, it controls the corresponding shutdown; user 2 sends a shutdown request instruction through APP2, and the cloud assigns it to service (2), then the light is controlled to remain in the off state. If user 1 then mistakenly triggers the shutdown request instruction through APP1, service (1) processes it and controls the light to turn on again.
[0028] While ensuring sequential control, the present invention adds a time control to avoid the problem of inaccurate control caused by the message time process. For example, after the cloud sends the received registration request to the corresponding service, the service starts to process the message after 2 minutes. Since the message is from 2 minutes ago, it is not the latest and has lost its timeliness, so there is no need to process it again. Therefore, after receiving the request message, each service of the present invention needs to make a timeliness judgment. If the time is too long and exceeds the set threshold, it means that the time limit has been exceeded and it will be discarded. The threshold is set to the maximum period perceived by the user, such as 3s.
[0029] In order to further improve the efficiency of control, after receiving the control instructions sent by the cloud after service processing, the gateway divides the instructions into queues according to the type of instruction information. The same type of instruction information is in one queue, and different types of instructions are in different queues. The queues in this embodiment include a first queue for storing single control instructions, a second queue for storing scene instructions, and a third queue for storing instructions sent by the system. That is, the first queue is used to store single control instructions, such as turning on the lights, turning off the lights, turning on the air conditioner, etc., and one instruction is for the control of one device; the second queue is used to store scene-type instructions, such as reading scenes and sleeping scenes, which are for the control of multiple devices; the third queue is used to store instructions sent by the system. For example, when the cloud wants to obtain the status of each home appliance, it will send such instructions through the gateway. In this way, different types of instructions can be stored and managed separately.
[0030] At the same time, taking into account the priority of control, the present invention reduces the priority of the first queue, the second queue and the third queue in sequence, that is, the priority of the single-control instruction is higher than the scene instruction, and the priority of the scene instruction is higher than the instruction issued by the system. When a single-control instruction is stored in the first queue, the gateway first forwards the single-control instruction. If there is no instruction in the first queue, it is determined whether there is a scene instruction in the second queue. If so, the gateway forwards the scene instruction. When there is no instruction in the first queue or the second queue, it is considered that the gateway is currently in an idle state. At this time, if there is an instruction in the third queue, it can be issued to the corresponding device.
Claims
1. A message sequence control method under a distributed architecture, It is characterized in that The method comprises the following steps: 1) Allocate services to each user in the cloud, making users and services relatively fixed; 2) After receiving the messages sent by the user, the cloud arranges them in queue order and assigns the messages to the service corresponding to the user, so that the messages sent by the same user are processed by the same service; 3) Each service processes the received message, obtains the corresponding instruction information, and sends the instruction information to the corresponding device.
2. The message sequence control method under the distributed architecture according to claim 1, It is characterized in that In step 3), each service needs to perform a time comparison after receiving the message. If the difference between the time the service receives the message and the time the user sends the message exceeds a set threshold, the message is considered invalid, the service will no longer process the message, and will re-request the corresponding user.
3. The message sequence control method under the distributed architecture according to claim 1 or 2, It is characterized in that Each service sends the command information to the corresponding device through the gateway.
4. The message sequence control method under the distributed architecture according to claim 3, It is characterized in that After receiving the instruction information, the gateway divides the instruction information into queues and stores it according to its type, with the same type of instruction information being in one queue and different types of instructions being in different queues.
5. The message sequence control method under the distributed architecture according to claim 4, It is characterized in that The queues include a first queue for storing single control instructions, a second queue for storing scene instructions, and a third queue for storing instructions issued by the system.
6. The message sequence control method under the distributed architecture according to claim 5, It is characterized in that The priorities of the first queue, the second queue and the third queue decrease in sequence.
7. The message sequence control method under a distributed architecture according to any one of claims 1 to 6, It is characterized in that In the step 1), a hash algorithm is used to allocate services to each user.
8. The message sequence control method under a distributed architecture according to any one of claims 1 to 6, It is characterized in that The step 2) is controlled by using a Kafka queue.
