Data processing method and device, medium and computer equipment
By storing message middleware client configuration information by pre-generated classes and subclasses, the target client is determined based on business requests, which solves the problem of repeated code development in the existing technology, improves code utilization and reduces development costs.
Patent Information
- Application Number
- CN202311269604.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-27
- Publication Date
- 2025-03-28
AI Technical Summary
In the prior art, the configuration information used by clients of each message middleware is different, resulting in the need to develop separately to realize the connection to each client, and there is a problem of repeated code development, the code utilization rate is low, and the development cost is high.
Through a pre-generated class, it includes multiple subclasses, each subclass corresponds to a message middleware, which is used to store the configuration information of the client corresponding to the message middleware. The target message middleware and target subclass are determined based on the business type to which the service request belongs, the target client is determined based on the configuration information in the target subclass, and the service data is sent to the target client.
It realizes the connection and service data transmission with clients of various message middleware through a unified piece of code, without the need to deploy different codes for different clients separately, which improves code utilization and reduces code development costs.
Smart Images

Figure CN119728413A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a data processing method and apparatus, a medium and a computer device. Background Art
[0002] In the related field, there are many message middlewares, and each message middleware has a corresponding client. The configuration information used by the clients of different message middlewares is often different. In the related art, it is necessary to develop the clients corresponding to each message middleware separately to realize the connection to each client. However, the above method has the problem of repeated code development, low code utilization rate and high development cost. Summary of the invention
[0003] In a first aspect, an embodiment of the present disclosure provides a data processing method, the method comprising: in response to receiving a business request, determining a target message middleware corresponding to a business type to which the business request belongs; obtaining a pre-generated class, the class comprising a plurality of subclasses, each subclass corresponding to a message middleware, the subclass being used to store configuration information of a client corresponding to the message middleware; obtaining a target subclass corresponding to the target message middleware; determining a target client corresponding to the target message middleware based on the configuration information in the target subclass; and sending business data to the target client.
[0004] In some embodiments, the clients corresponding to the target message middleware include a primary client and a backup client; the configuration information in the target subclass includes switching information for indicating a switching strategy between the primary client and the backup client; and determining the target client corresponding to the target message middleware based on the configuration information in the target subclass includes: determining the target client from the primary client and the backup client based on the switching information in the target subclass.
[0005] In some embodiments, the determining of the target client from the primary client and the backup client based on the switching information in the target subclass includes: if the primary client does not meet the switching condition, determining the primary client as the target client; if the primary client meets the switching condition, determining the backup client as the target client; the switching condition is determined based on the switching policy indicated by the switching information in the target subclass.
[0006] In some embodiments, if the primary client meets the switching condition, determining the backup client as the target client includes: if the primary client meets the switching condition and the backup client does not meet the switching condition, determining the backup client as the target client.
[0007] In some embodiments, the number of clients corresponding to the target message middleware is greater than 1; the configuration information in the target subclass includes load balancing information for indicating the load balancing strategy of multiple clients corresponding to the target message middleware; determining the target client corresponding to the target message middleware based on the configuration information in the target subclass includes: determining the target client from the multiple clients corresponding to the target message middleware based on the load balancing information in the target subclass.
[0008] In some embodiments, the clients corresponding to the target message middleware include primary clients and backup clients, and the number of the primary clients and / or the number of the backup clients is greater than 1; determining the target client from the multiple clients corresponding to the target message middleware based on the load balancing information in the target subclass includes: determining the target client from the primary clients corresponding to the target message middleware based on the load balancing information in the target subclass; if the primary client corresponding to the target message middleware is empty, or the target client determined from the primary clients corresponding to the target message middleware is in an abnormal state, determining the target client from the backup clients corresponding to the target message middleware based on the load balancing information.
[0009] In some embodiments, the configuration information in the target subclass includes detection information for indicating a status detection strategy for the target client; determining the target client corresponding to the target message middleware based on the configuration information in the target subclass includes: performing status detection on at least one client corresponding to the target subclass based on the detection information in the target subclass; and determining a client in a normal state among the clients corresponding to the target subclass as a target client.
[0010] In some embodiments, the business request carries identification information for identifying the message middleware, and each subclass carries identification information of the corresponding message middleware; obtaining the target subclass corresponding to the target message middleware includes: if the identification information carried in the first subclass among the multiple subclasses is the same as the identification information carried in the business request, determining the first subclass as the target subclass.
[0011] In some embodiments, each subclass is stored in the class in sequence, and the business request carries numbering information to indicate the position of the subclass corresponding to the target message middleware in the class; obtaining the target subclass corresponding to the target message middleware includes: determining the target subclass based on the numbering information carried in the business request.
[0012] In some embodiments, obtaining the target subclass corresponding to the target message middleware includes: displaying a list of subclasses corresponding to each message middleware in response to the service request; and determining a subclass selected from the list as the target subclass.
[0013] In some embodiments, the configuration information in the target subclass includes client creation information for indicating a method for creating a target client; before determining the target client corresponding to the target message middleware based on the configuration information in the target subclass, the method further includes: creating the target client based on the client creation information in the target subclass.
[0014] In a second aspect, an embodiment of the present disclosure provides a data processing device, which includes: a first determination module, used to determine, in response to receiving a business request, a target message middleware corresponding to a business type to which the business request belongs; a first acquisition module, used to obtain a pre-generated class, the class including multiple subclasses, each subclass corresponding to a message middleware, and the subclass being used to store configuration information of a client of the corresponding message middleware; a second acquisition module, used to obtain a target subclass corresponding to the target message middleware; a second determination module, used to determine a target client corresponding to the target message middleware based on the configuration information in the target subclass; and a sending module, used to send business data to the target client.
[0015] In some embodiments, the clients corresponding to the target message middleware include a primary client and a backup client; the configuration information in the target subclass includes switching information for indicating a switching strategy between the primary client and the backup client; the second determination module is specifically used to: determine the target client from the primary client and the backup client based on the switching information in the target subclass.
[0016] In some embodiments, the second determination module is specifically used to: if the primary client does not meet the switching condition, determine the primary client as the target client; if the primary client meets the switching condition, determine the backup client as the target client; the switching condition is determined based on the switching policy indicated by the switching information in the target subclass.
[0017] In some embodiments, the second determination module is specifically configured to: if the primary client meets the switching condition and the backup client does not meet the switching condition, determine the backup client as the target client.
[0018] In some embodiments, the number of clients corresponding to the target message middleware is greater than 1; the configuration information in the target subclass includes load balancing information for indicating the load balancing strategy of multiple clients corresponding to the target message middleware; the second determination module is specifically used to: determine the target client from the multiple clients corresponding to the target message middleware based on the load balancing information in the target subclass.
[0019] In some embodiments, the clients corresponding to the target message middleware include primary clients and backup clients, and the number of the primary clients and / or the number of the backup clients is greater than 1; the second determination module is specifically used to: determine the target client from the primary clients corresponding to the target message middleware based on the load balancing information in the target subclass; if the primary client corresponding to the target message middleware is empty, or the target client determined from the primary clients corresponding to the target message middleware is in an abnormal state, determine the target client from the backup clients corresponding to the target message middleware based on the load balancing information.
[0020] In some embodiments, the configuration information in the target subclass includes detection information for indicating a status detection strategy for the target client; the second determination module is specifically used to: perform status detection on at least one client corresponding to the target subclass based on the detection information in the target subclass; and determine a client in a normal state among the clients corresponding to the target subclass as a target client.
[0021] In some embodiments, the business request carries identification information for identifying the message middleware, and each subclass carries identification information of the corresponding message middleware; the second acquisition module is specifically used to: if the identification information carried in the first subclass among the multiple subclasses is the same as the identification information carried in the business request, determine the first subclass as the target subclass.
[0022] In some embodiments, each subclass is stored in the class in sequence, and the business request carries numbering information to indicate the position of the subclass corresponding to the target message middleware in the class; the second acquisition module is specifically used to determine the target subclass based on the numbering information carried in the business request.
[0023] In some embodiments, the second acquisition module is specifically used to: display a list of subclasses corresponding to each message middleware in response to the business request; and determine a subclass selected from the list as a target subclass.
[0024] In some embodiments, the configuration information in the target subclass includes client creation information for indicating a method for creating a target client; before determining the target client corresponding to the target message middleware based on the configuration information in the target subclass, the device also includes: a creation module for creating the target client based on the client creation information in the target subclass.
[0025] In a third aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any embodiment of the present disclosure.
[0026] In a fourth aspect, an embodiment of the present disclosure provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in any embodiment of the present disclosure when executing the program.
[0027] In the disclosed embodiment, the configuration information of the client of each message middleware is encapsulated in a subclass corresponding to the message middleware, and each subclass is added to the class. After receiving a business request, the target subclass can be determined according to the target message middleware corresponding to the business type to which the business request belongs, and the target client corresponding to the target message middleware can be determined according to the configuration information in the target subclass, thereby sending business data to the target client. In this way, the disclosed embodiment realizes the connection with the clients of various message middleware and the sending of business data through a unified code, without the need to deploy different codes for different clients, thereby improving code utilization and reducing code development costs.
[0028] It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The drawings herein are incorporated into the specification and constitute a part of the present disclosure. These drawings illustrate embodiments consistent with the present disclosure and are used to illustrate the technical solutions of the present disclosure together with the specification.
[0030] Figure 1 It is a flow chart of the data processing method of the embodiment of the present disclosure.
[0031] Figure 2 It is a schematic diagram of the class of the embodiment of the present disclosure.
[0032] Figure 3 It is a schematic diagram of a configuration model of an embodiment of the present disclosure.
[0033] Figure 4 It is an overall flow chart of an embodiment of the present disclosure.
[0034] Figure 5 It is a block diagram of a data processing device according to an embodiment of the present disclosure.
[0035] Figure 6 is a schematic diagram of a computer device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0036] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0037] The terms used in this disclosure are only for the purpose of describing specific embodiments and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items. In addition, the term "at least one" herein means any combination of at least two of any one or more of a plurality of.
[0038] It should be understood that although the terms first, second, third, etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0039] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present disclosure and to make the above-mentioned purposes, features and advantages of the embodiments of the present disclosure more obvious and understandable, the technical solutions in the embodiments of the present disclosure are further described in detail below in conjunction with the accompanying drawings.
[0040] In the relevant field, there are many message middlewares such as Pulsar message middleware, RabbitMQ message middleware, Kafka message middleware, etc. The configuration information used by the clients of different message middlewares is often different. For example, the client of the message middleware has functional requirements such as load balancing, heartbeat detection, and master-slave switching, but the load balancing strategy, heartbeat detection strategy, and master-slave switching strategy used by the clients of different message middlewares are often different. Therefore, in the relevant technology, it is necessary to deploy different configuration information and corresponding codes in different clients respectively, so that the client can be connected smoothly in the business scenario. However, the above method has the problem of repeated code development, resulting in low code utilization and high development cost.
[0041] Based on this, the present disclosure provides a data processing method, see Figure 1 , the method comprising:
[0042] Step S1: in response to receiving a service request, determining a target message middleware corresponding to a service type to which the service request belongs;
[0043] Step S2: obtaining a pre-generated class, which includes multiple subclasses, each subclass corresponds to a message middleware, and the subclass is used to store configuration information of the client corresponding to the message middleware;
[0044] Step S3: Obtain the target subclass corresponding to the target message middleware;
[0045] Step S4: determining the target client corresponding to the target message middleware based on the configuration information in the target subclass;
[0046] Step S5: Sending service data to the target client.
[0047] The disclosed embodiment encapsulates the configuration information of the client of each message middleware in a subclass corresponding to the message middleware, and adds each subclass to the class. After receiving a business request, the target subclass can be determined according to the target message middleware corresponding to the business type to which the business request belongs, and the target client corresponding to the target message middleware can be determined according to the configuration information in the target subclass, thereby sending business data to the target client. In this way, the disclosed embodiment realizes the connection with the clients of various message middleware and the sending of business data through a unified code, without the need to deploy different codes for different clients respectively, thereby improving code utilization and reducing code development costs. In addition, after the types of message middleware are increased, the connection to the client corresponding to the newly added message middleware can be realized by adding a new subclass in the class, thereby improving the scalability of the solution. The scheme of the disclosed embodiment is illustrated below.
[0048] The method of the embodiment of the present disclosure can be implemented by deploying code in a unified starter. Optionally, the starter can be implemented based on the spring-boot framework, and the above starter can be called spring-boot-starter.
[0049] In step S1, spring-boot-starter can receive a business request. For example, in a takeaway order scenario, a user can order food on a takeaway platform and generate a takeaway order. One or more business requests can be generated based on the takeaway order, including but not limited to a user asset update request, an inventory update request, an order allocation request for allocating a delivery order to a delivery capacity, and the like. These business requests can be received by spring-boot-starter. Among them, the business type to which the user asset update request belongs is the asset update type, the business type to which the inventory update request belongs is the inventory update type, and the business type to which the order allocation request belongs is the order allocation type. Different business types may correspond to the same or different message middleware. For example, a business request of the asset update type corresponds to the pulsar message middleware, the inventory update type corresponds to the rabbitmq message middleware, and the order allocation type corresponds to the kafka message middleware. The correspondence between each business type and the message middleware can be established and stored in advance. Assuming that the currently received business request is an order allocation request, the kafka message middleware can be determined as the target message middleware.
[0050] It is understood that this is only an exemplary description and is not intended to limit the present disclosure. The application scenarios applicable to the embodiments of the present disclosure may also be other scenarios besides the takeaway order scenario, and the types of business requests and their corresponding message middleware are not limited to those described in the aforementioned embodiments.
[0051] In step S2, a class including multiple subclasses can be pre-generated. Wherein, each subclass corresponds to a message middleware. Continuing with the previous example, when the types of message middleware include pulsar message middleware, rabbitmq message middleware and kafka message middleware, the class includes three subclasses, namely: a subclass corresponding to pulsar message middleware, a subclass corresponding to rabbitmq message middleware, and a subclass corresponding to kafka message middleware. Each subclass is used to store the configuration information of the client of the corresponding message middleware, for example, the subclass corresponding to pulsar message middleware is used to store the configuration information of the client of pulsar message middleware, the subclass corresponding to rabbitmq message middleware is used to store the configuration information of the client of rabbitmq message middleware, and the subclass corresponding to kafka message middleware is used to store the configuration information of the client of kafka message middleware. Wherein, the configuration information of the client is used to connect to the client, and the configuration information of the clients of different message middleware can be the same or different. The above three subclasses can be encapsulated in the same class. The following is an example of each message middleware's corresponding subclass and its configuration information.
[0052] In some embodiments, the client corresponding to each message middleware includes at least one master client and at least one backup client. The connection priority of the master client is higher than the connection priority of the backup client. That is to say, when the master client is in a normal state, the master client is connected first and business data is sent to the master client. Only when the master client is in an abnormal state, the backup client is connected and business data is sent to the backup client. The subclass corresponding to the message middleware may include switching information for indicating the switching strategy between the master client and the backup client corresponding to the message middleware. The switching information may be a specific switching strategy or an identifier for identifying the switching strategy. The identifier may include at least one of numbers, letters, and symbols. Different switching strategies correspond to different identifiers. The switching strategies adopted by the clients of different message middleware may be different. The switching strategy may be to disable the master client and enable the backup client (switching strategy based on duration) when the duration of the master client being in an abnormal state is greater than a preset duration threshold, or to disable the master client and enable the backup client (switching strategy based on duration) when the number of times the master client is detected to be in an abnormal state is greater than a preset number threshold, or to disable the master client and enable the backup client (switching strategy based on number), or it may be a switching strategy based on other conditions. Different switching strategies may refer to switching strategies based on different conditions, or switching strategies based on the same condition but with different parameters (eg, the above-mentioned preset duration threshold or preset number threshold) used in the switching strategies.
[0053] In some embodiments, the number of clients corresponding to each message middleware may be greater than 1. The subclass corresponding to the message middleware may include load balancing information for indicating the load balancing strategy of multiple clients corresponding to the message middleware. Among them, by adding a load balancing strategy in the subclass corresponding to the message middleware, the load balancing of multiple clients corresponding to the message middleware can be achieved. The load balancing strategy can be a random balancing strategy, that is, randomly selecting one from multiple clients as the target client, or it can be a polling strategy, that is, selecting one from multiple clients as the target client by polling. The load balancing strategies adopted by the clients of different message middleware may be different.
[0054] Furthermore, in the case where the client corresponding to the message middleware includes a primary client and a backup client, the number of any one of the primary client and the backup client may be greater than 1. In the case where the number of primary clients corresponding to the message middleware is greater than 1, the load balancing policy corresponding to the message middleware may be used to load balance multiple primary clients based on the load balancing information in the subclass corresponding to the message middleware. Similarly, in the case where the number of backup clients corresponding to the message middleware is greater than 1, the load balancing policy corresponding to the message middleware may be used to load balance multiple backup clients based on the load balancing information in the subclass corresponding to the message middleware. Among them, the load balancing policy used to load balance the primary client may be the same as or different from the load balancing policy used to load balance the backup client. In the case where the two are different, the corresponding subclass must include both the load balancing information for indicating the load balancing policy for multiple primary clients and the load balancing information for indicating the load balancing policy for multiple backup clients, and the two types of load balancing information must be identified respectively.
[0055] In some embodiments, the configuration information in the subclass corresponding to the message middleware may include detection information for indicating a state detection strategy for the client of the message middleware. The state detection strategy is used to detect the state of the client, and the state of the client includes a normal state and an abnormal state. The state detection strategies adopted by the clients of different message middleware may be different. The state detection strategy may include but is not limited to at least one of heartbeat detection, response time detection, network connectivity detection, log monitoring, etc.
[0056] In some embodiments, the configuration information in the subclass corresponding to the message middleware may include client creation information for indicating the creation method of the target client. For example, the client creation information may be used to determine the type and quantity of the created client.
[0057] In addition to the several types of configuration information listed above, the subclass corresponding to the message middleware may also include other configuration information, which can be determined according to actual needs and will not be listed here one by one.
[0058] In step S3, the target subclass corresponding to the target message middleware may be obtained. The following provides examples of several specific methods for determining the target subclass.
[0059] In some embodiments, identification information can be added to each subclass to uniquely identify each subclass. Identification information can also be carried in the business request, so that after receiving the business request, spring-boot-starter can compare the identification information carried in the business request with the identification information in each subclass. If the identification information included in a subclass (referred to as the first subclass) among multiple subclasses is the same as the identification information carried in the business request, the first subclass is determined as the target subclass. Optionally, the business type (buName) corresponding to the message middleware can be used as the identification information of the subclass corresponding to the message middleware. Assuming that the identification information carried in the business request is buName1, and the identification information in each subclass is buName1, buName2, ..., buNamen, the subclass carrying the identification information buName1 can be determined as the target subclass. By assigning identification information to the message middleware, different message middleware can be quickly distinguished. After obtaining the business request, the target subclass can be determined directly by comparing the identification information carried in the business request with the identification information in each subclass, thereby improving the efficiency of determining the target subclass.
[0060] In other embodiments, each subclass can be stored in the class in sequence. For example, the subclass corresponding to business type 1 is stored as the first subclass in the class, the subclass corresponding to business type 2 is stored as the second subclass in the class, and so on. The business request can carry numbering information to indicate the position of the subclass corresponding to the target message middleware in the class, so that after receiving the business request, spring-boot-starter can determine the target subclass based on the numbering information carried in the business request. For example, assuming that the numbering information carried in the business request is "2", the second subclass in the class can be determined as the target subclass. In this embodiment, each subclass is stored in the class in sequence, so that based on the numbering information carried in the business request, the subclass of the corresponding storage position can be directly read from the class and used as the target subclass. This method can simply and efficiently determine the target subclass from each subclass.
[0061] In some embodiments, a list of subclasses corresponding to each message middleware can also be displayed in response to a business request, and a subclass selected from the list can be determined as a target subclass. For example, assuming that the class includes subclass 1, subclass 2, and subclass 3, a list including subclass 1, subclass 2, and subclass 3 can be displayed to the user in response to a business request, and the user can select one from them as a target subclass. Assuming that the target selected subclass is subclass 3, subclass 3 can be determined as the target subclass. This embodiment can intuitively display a list of subclasses corresponding to each message middleware to the user in response to a business request, and the user can select a target subclass from it, thereby improving the user's autonomy in the process of determining the target subclass.
[0062] The above embodiments provide a variety of optional methods for determining the target subclass, and the user can select any method according to actual needs. The processing method has a high scope of application and flexibility.
[0063] In step S4, after the target subclass is determined, the target client corresponding to the target message middleware can be determined according to the configuration information in the target subclass. The specific method of determining the target client is described below with reference to various configuration information in the above embodiments.
[0064] If the configuration information includes switching information for indicating a switching strategy between the primary client and the backup client, the target client can be determined from the primary client and the backup client corresponding to the target message middleware based on the switching information in the target subclass. This embodiment can implement the primary and backup switching between the primary client and the backup client by adding the switching information in the subclass, thereby improving the reliability and redundancy of the client.
[0065] Specifically, if the primary client does not meet the switching condition, the primary client is determined as the target client. If the primary client meets the switching condition, the backup client is determined as the target client. Among them, the switching condition is determined based on the switching strategy indicated by the switching information in the target subclass. Assuming that the switching strategy is the duration-based switching strategy in the aforementioned embodiment, the switching condition may be that the duration of the primary client being in an abnormal state is greater than a preset duration threshold. Assuming that the switching strategy is the number-based switching strategy in the aforementioned embodiment, the switching condition may be that the number of times the primary client is in an abnormal state is greater than a preset number threshold. In the case where the switching strategy is other strategies, other switching conditions can also be set accordingly, which are not listed here one by one. By adopting the above method, in the case of an abnormality of the primary client, the business data can be processed by the backup client, thereby realizing redundant backup of the primary client by the backup client.
[0066] In the case where the primary client satisfies the switching condition, it is further possible to determine whether the backup client satisfies the switching condition. If the backup client does not satisfy the switching condition, the backup client is determined as the target client. If the backup client satisfies the switching condition, a prompt message indicating that the target client is not found is returned. This embodiment further determines whether the backup client satisfies the switching condition on the basis of determining whether the primary client satisfies the switching condition. The backup client is determined as the target client only when the primary client satisfies the switching condition and the backup client does not satisfy the switching condition, thereby reducing the problem that the backup client cannot process data normally after switching due to the backup client satisfying the switching condition (for example, the backup client is abnormal), and further improving the reliability of the client.
[0067] If the configuration information includes load balancing information for indicating the load balancing strategy of multiple clients corresponding to the target message middleware, the target client can be determined from the multiple clients corresponding to the target message middleware based on the load balancing information in the target subclass. For example, in the case where the load balancing strategy is to randomly select one from multiple clients as the target client, the client randomly selected from the multiple clients corresponding to the target message middleware can be determined as the target client. In the case where the load balancing strategy is to select one from multiple clients as the target client by polling, the multiple clients corresponding to the target message middleware can be polled to obtain the target client. This embodiment can achieve load balancing among multiple clients by adding load balancing information in the subclass, reduce the situation where a single client is overloaded and causes data processing performance to decrease, and at the same time can utilize the processing resources of multiple clients to improve the processing efficiency of business data.
[0068] Further, in the case where the configuration information includes both switching information and load balancing information, the target client can be selected from one or more main clients corresponding to the target message middleware based on the load balancing information. If the main client corresponding to the target message middleware is empty, or the target client determined from each main client corresponding to the target message middleware is in an abnormal state, the target client is determined from each backup client corresponding to the target message middleware based on the load balancing information. This embodiment realizes both master-slave switching and load balancing. On the one hand, the target client can be selected from one or more main clients first. Only when the main client corresponding to the target message middleware is empty, or the target client determined from each main client corresponding to the target message middleware is in an abnormal state, the target client is determined from the backup client, thereby realizing redundant backup of the main client by the backup client and improving the stability of the client; on the other hand, whether the target client is determined from the main client or from the backup client, a load balancing strategy is adopted, thereby reducing the situation where the data processing performance is reduced due to the overload of each main client and each backup client.
[0069] For example, assuming that the primary clients corresponding to the target message middleware include client 11, client 12, and client 13, and the backup clients corresponding to the target message middleware include client 21, client 22, and client 23, and assuming that the load balancing strategy is to randomly select one client from multiple clients as the target client, then you can first randomly determine a client from client 11, client 12, and client 13, assuming it is client 11. Then determine whether client 11 meets the switching condition corresponding to the switching strategy indicated by the switching information. If not, client 11 is determined as the target client. If satisfied, then randomly select one from client 21, client 22, and client 23 as the target client, assuming it is client 21. Thus, the target client finally determined is client 21.
[0070] If the configuration information includes detection information for indicating a state detection strategy for the target client, then the state detection can be performed on at least one client corresponding to the target subclass based on the detection information in the target subclass, and the client in the normal state among the clients corresponding to the target subclass can be determined as the target client. Among them, the detection method for performing state detection on each client corresponding to the target subclass can be determined based on the state detection strategy indicated by the detection information in the target subclass. For example, if the state detection strategy is heartbeat detection, a heartbeat packet can be sent to each client corresponding to the target subclass at every preset time t. If a response packet returned by the client is received, it is determined that the client is in a normal state, otherwise it is determined that the client is in an abnormal state. By performing state detection, abnormal clients can be discovered in time and abnormal processing can be performed, thereby improving the stability and reliability of the client and ensuring the high availability of data processing services.
[0071] In the case where the configuration information includes switching information, load balancing information, and detection information at the same time, the target client can be selected from one or more primary clients corresponding to the target message middleware based on the load balancing information, and then the status of the client selected from the primary client can be detected based on the detection information. If the client is in a normal state, the client is determined as the target client. If the client is in an abnormal state, it is determined whether the switching condition is met based on the switching information. If it is met, the target client is selected from one or more backup clients corresponding to the target message middleware.
[0072] In the case where the configuration information in the target subclass includes client creation information for indicating the creation method of the target client, the target client can also be created based on the client creation information in the target subclass. The client creation information may include the Uniform Resource Locator (URL) of the message middleware server to which the target client is connected, the connection timeout period between the target client and the message middleware server, and the maximum number of message producers and message consumers connected to the message middleware server through the target client. The user can configure the client creation information, and after configuring the client creation information, a target client matching the client creation information can be created.
[0073] In step S5, business data can be sent to the target client. For example, in the takeaway order scenario in the aforementioned embodiment, when the business request is a user asset update request, the target client is determined to be the client corresponding to the pulsar message middleware, and the business data related to the asset update is sent to the client. When the business request is an inventory update request, the target client is determined to be the client corresponding to the rabbitmq message middleware, and the business data related to the inventory update is sent to the client. When the business request is an order allocation request, the target client is determined to be the client corresponding to the kafka message middleware, and the business data related to the order allocation is sent to the client.
[0074] Figure 2 The classes of some embodiments are shown, which can be a factory class, called X1, and the subclass in the factory class is called X2. The factory class X1 can implement the IF interface. By calling the interface, any method in method 1, method 2 and method 3 can be executed to determine the target subclass. Among them, method 1 is a method for determining the target subclass based on the identification information carried in the business request, method 2 is a method for determining the target subclass based on the number carried in the business request, and method 3 is a method for determining the target subclass based on the list of subclasses corresponding to each message middleware. Subclass X2 can implement the LB interface and the CF interface. Among them, the load balancing method can be executed by calling the LB interface, and the method can realize load balancing for each client based on the load balancing strategy. The client acquisition method can be executed by calling the CF interface, and the client acquisition method can determine the target client based on the state detection strategy, etc. In addition, the factory class X1 can also include an initialization method. Before executing the data processing method of the embodiment of the present disclosure, the method in the initialization object can be executed to perform the initialization operation. After initialization, the application loading method can be executed to load the factory class X1 into the application context. After the loading is completed, the data processing method of the embodiment of the present disclosure can be executed.
[0075] like Figure 2 As shown, subclass X2 includes an initialization method, a client ID acquisition method, a load balancing strategy, a health detection method, a client creation method, a method for calling a health detection method to obtain a client status (referred to as a status acquisition method), a method for calling a load balancing strategy to obtain a client (referred to as a load balancing method), and a client acquisition method for calling a status acquisition method and a load balancing method to obtain a target client.
[0076] The factory class X1 includes an initialization method, a method for determining the target subclass corresponding to the target client, a method for obtaining a message consumer mapping list, a method for obtaining a message producer mapping list, a method for obtaining BuName, a method for setting BuName, a method for creating the factory class X1, a method for setting the factory class to the context information, a post-setting method after initialization, a method for obtaining the target subclass corresponding to the target client through the client ID, a method for creating a client, a method for obtaining a client, and a method for obtaining a list of BuNames.
[0077] The method of the embodiment of the present disclosure can be based on Figure 3 The client configuration model shown is implemented as a three-layer model. The outermost layer is the identification information (buName) layer, which is used to determine the target subclass; the middle layer is the primary-backup layer, which is used to determine the target client from the primary client or the backup client; the innermost layer is the connection information layer. When the target client is the primary client, a piece of connection information in the primary client is selected, so that the primary client corresponding to the connection information is determined as the target client and connected; when the target client is the backup client, a piece of connection information in the backup client is selected, so that the backup client corresponding to the connection information is determined as the target client and connected. In some embodiments, the connection information may include the client's Uniform Resource Locator (URL), user name, and password.
[0078] See also Figure 4 The overall process of the solution of the embodiment of the present disclosure is as follows:
[0079] Step 1: Based on the spring boot automatic assembly function, Figure 3 The configuration model in is loaded into memory.
[0080] Step 2: Create the X1 factory class and submit it to the spring bean object container.
[0081] Step 3: After executing the application loading method to load the factory class X1 into the application context, obtain the object storing the connection information, initialize the configuration information and create the client. This includes the following sub-steps:
[0082] 3.1 Initialize the configuration information of each primary client and backup client, the identification information set of the message middleware, the configuration information list of the message consumer, the configuration information list of the message producer, and the status of each client. Among them, the message producer can generate messages and send the generated messages to the message consumer for consumption by calling the message middleware. Both the message producer and the message consumer can be services provided by the application. It is understandable that the same service can be both a message producer and a message consumer.
[0083] 3.2 Call the client creation method to create a client based on the configuration information.
[0084] 3.3 Create a detection thread based on the detection information indicating the state detection strategy.
[0085] Step 4: Get the target client. This includes the following sub-steps:
[0086] 4.1 First, determine the target subclass X2 from the primary connection mapping of the factory class X1 through the identification information (buName). If buName does not exist, an exception prompt is output. If the target subclass X2 is not obtained from the primary connection mapping, obtain the target subclass X2 from the backup connection mapping of X1 and return it.
[0087] 4.2 Based on the target subclass X2, a target client in normal state is selected and returned through load balancing strategies such as polling.
[0088] See also Figure 5 The present disclosure also provides a data processing device, the device comprising:
[0089] A first determination module 11 is used to determine, in response to receiving a service request, a target message middleware corresponding to a service type to which the service request belongs;
[0090] A first acquisition module 12 is used to acquire a pre-generated class, wherein the class includes a plurality of subclasses, each subclass corresponds to a message middleware, and the subclass is used to store configuration information of a client corresponding to the message middleware;
[0091] The second acquisition module 13 is used to acquire the target subclass corresponding to the target message middleware;
[0092] A second determination module 14, configured to determine a target client corresponding to the target message middleware based on the configuration information in the target subclass;
[0093] The sending module 15 is used to send service data to the target client.
[0094] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0095] An embodiment of the present disclosure further provides a computer device, which at least includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method described in any of the above embodiments is implemented.
[0096] Figure 6A more specific hardware structure diagram of a computing device provided by an embodiment of the present disclosure is shown, and the device may include: a processor 21, a memory 22, an input / output interface 23, a communication interface 24, and a bus 25. The processor 21, the memory 22, the input / output interface 23, and the communication interface 24 are connected to each other in communication within the device through the bus 25.
[0097] The processor 21 can be implemented by a general central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), or one or more integrated circuits, etc., for executing relevant programs to implement the technical solutions provided by the embodiments of the present disclosure. The processor 21 can also include a graphics card, which can be a Nvidia titan X graphics card or a 10120Ti graphics card, etc.
[0098] The memory 22 can be implemented in the form of a read-only memory (ROM), a random access memory (RAM), a static storage device, a dynamic storage device, etc. The memory 22 can store an operating system and other application programs. When the technical solution provided by the embodiment of the present disclosure is implemented by software or firmware, the relevant program code is stored in the memory 22 and called and executed by the processor 21.
[0099] The input / output interface 23 is used to connect the input / output module to realize information input and output. The input / output module can be configured as a component in the device (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0100] The communication interface 24 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0101] The bus 25 includes a path that transmits information between the various components of the device (eg, the processor 21, the memory 22, the input / output interface 23, and the communication interface 24).
[0102] It should be noted that, although the above device only shows the processor 21, the memory 22, the input / output interface 23, the communication interface 24 and the bus 25, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present disclosure, and does not necessarily include all the components shown in the figure.
[0103] The present disclosure also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method described in any of the above embodiments is implemented.
[0104] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0105] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the embodiments of the present disclosure can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the embodiments of the present disclosure is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a disk, an optical disk, etc., including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present disclosure or some parts of the embodiments.
[0106] The systems, devices, modules or units described in the above embodiments may be implemented by computer devices or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0107] Each embodiment in the present disclosure is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The device embodiment described above is merely schematic, wherein the modules described as separate components may or may not be physically separated, and the functions of each module can be implemented in the same one or more software and / or hardware when implementing the embodiment of the present disclosure. It is also possible to select some or all of the modules according to actual needs to achieve the purpose of the embodiment. A person of ordinary skill in the art can understand and implement it without paying creative labor.
[0108] The above is only a specific implementation of the embodiment of the present disclosure. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the embodiment of the present disclosure. These improvements and modifications should also be regarded as the protection scope of the embodiment of the present disclosure.
Claims
1. A data processing method, the method comprising: In response to receiving a service request, determining a target message middleware corresponding to a service type to which the service request belongs; Obtain a pre-generated class, wherein the class includes multiple subclasses, each subclass corresponds to a message middleware, and the subclass is used to store configuration information of a client corresponding to the message middleware; Obtain the target subclass corresponding to the target message middleware; Determine a target client corresponding to the target message middleware based on the configuration information in the target subclass; Sending service data to the target client.
2. According to the method of claim 1, the client corresponding to the target message middleware includes a primary client and a backup client; the configuration information in the target subclass includes switching information for indicating a switching strategy between the primary client and the backup client; the determining the target client corresponding to the target message middleware based on the configuration information in the target subclass comprises: Based on the switching information in the target subclass, a target client is determined from the primary client and the backup client.
3. The method according to claim 2, wherein determining the target client from the primary client and the backup client based on the switching information in the target subclass comprises: If the master client does not meet the switching condition, determining the master client as the target client; If the primary client meets the switching condition, determining the backup client as the target client; The switching condition is determined based on a switching strategy indicated by the switching information in the target subclass.
4. The method according to claim 3, wherein if the primary client satisfies the switching condition, determining the backup client as the target client comprises: If the primary client meets the switching condition, and the backup client does not meet the switching condition, the backup client is determined as the target client.
5. According to the method of claim 1, the number of clients corresponding to the target message middleware is greater than 1; the configuration information in the target subclass includes load balancing information for indicating a load balancing strategy for multiple clients corresponding to the target message middleware; the determining the target client corresponding to the target message middleware based on the configuration information in the target subclass comprises: A target client is determined from a plurality of clients corresponding to the target message middleware based on the load balancing information in the target subclass.
6. The method according to claim 5, wherein the client corresponding to the target message middleware includes a primary client and a backup client, and the number of the primary clients and / or the number of the backup clients is greater than 1; The determining the target client from the multiple clients corresponding to the target message middleware based on the load balancing information in the target subclass includes: Determine a target client from each main client corresponding to the target message middleware based on the load balancing information in the target subclass; If the primary client corresponding to the target message middleware is empty, or the target client determined from the primary clients corresponding to the target message middleware is in an abnormal state, the target client is determined from the backup clients corresponding to the target message middleware based on the load balancing information.
7. According to the method of claim 1, the configuration information in the target subclass includes detection information for indicating a state detection strategy for the target client; and the determining the target client corresponding to the target message middleware based on the configuration information in the target subclass comprises: Performing status detection on at least one client corresponding to the target subclass based on the detection information in the target subclass; A client in a normal state among the clients corresponding to the target subclass is determined as a target client.
8. According to the method of claim 1, the business request carries identification information for identifying the message middleware, and each subclass carries identification information of the corresponding message middleware; and obtaining the target subclass corresponding to the target message middleware comprises: If the identification information carried in a first subclass among the multiple subclasses is the same as the identification information carried in the service request, the first subclass is determined as the target subclass.
9. According to the method of claim 1, each subclass is stored in the class in sequence, and the service request carries number information for indicating the position of the subclass corresponding to the target message middleware in the class; the step of obtaining the target subclass corresponding to the target message middleware comprises: The target subclass is determined based on the numbering information carried in the service request.
10. According to the method of claim 1, the step of obtaining the target subclass corresponding to the target message middleware comprises: In response to the business request, a list of subclasses corresponding to each message middleware is displayed; A subclass selected from the list is determined as a target subclass.
11. The method according to claim 1, wherein the configuration information in the target subclass includes client creation information for indicating a creation method of a target client; before determining the target client corresponding to the target message middleware based on the configuration information in the target subclass, the method further comprises: The target client is created based on the client creation information in the target subclass.
12. A data processing device, comprising: A first determination module, configured to determine, in response to receiving a service request, a target message middleware corresponding to a service type to which the service request belongs; A first acquisition module is used to acquire a pre-generated class, wherein the class includes a plurality of subclasses, each subclass corresponds to a message middleware, and the subclass is used to store configuration information of a client corresponding to the message middleware; A second acquisition module is used to acquire a target subclass corresponding to the target message middleware; A second determination module, configured to determine a target client corresponding to the target message middleware based on the configuration information in the target subclass; The sending module is used to send business data to the target client.
13. A computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the method according to any one of claims 1 to 11 is implemented.
14. An authorization authentication platform, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in any one of claims 1 to 11 when executing the program.