CN114996181B - Interface routing method and device, electronic equipment and storage medium - Google Patents

Interface routing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114996181B
CN114996181B CN202110231182.3A CN202110231182A CN114996181B CN 114996181 B CN114996181 B CN 114996181B CN 202110231182 A CN202110231182 A CN 202110231182A CN 114996181 B CN114996181 B CN 114996181B
Authority
CN
China
Prior art keywords
routing
parameter
target
implementation
interface
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.)
Active
Application number
CN202110231182.3A
Other languages
Chinese (zh)
Other versions
CN114996181A (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.)
Beijing Tongbang Zhuoyi Technology Co ltd
Original Assignee
Beijing Tongbang Zhuoyi Technology 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 Beijing Tongbang Zhuoyi Technology Co ltd filed Critical Beijing Tongbang Zhuoyi Technology Co ltd
Priority to CN202110231182.3A priority Critical patent/CN114996181B/en
Publication of CN114996181A publication Critical patent/CN114996181A/en
Application granted granted Critical
Publication of CN114996181B publication Critical patent/CN114996181B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/382Information transfer, e.g. on bus using universal interface adapter
    • G06F13/385Information transfer, e.g. on bus using universal interface adapter for adaptation of a particular data processing system to different peripheral devices

Abstract

The application relates to a routing method, a device, electronic equipment and a storage medium of an interface, which are applied to the technical field of computers, wherein the method comprises the following steps: obtaining an implementation request of a target interface, wherein the implementation request of the target interface comprises a routing entry; obtaining a routing rule corresponding to a target interface; obtaining the realization class of each interface of the service providing system; and determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rules and the routing parameters so as to complete the implementation of the target interface through the target implementation class. The method solves the problems that in the related art, for each implementation class of each interface, the implementation class of the interface needs to be registered first to route to the implementation class, and the operation process is complex.

Description

Interface routing method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computers, and in particular, to a method and apparatus for routing an interface, an electronic device, and a storage medium.
Background
Different customers implement the same function differently for the platform item and the floor item. In a specific application, different routing rules may exist in different implementation scenarios, for example, the current class implements multiple interfaces at the same time, and the routing rules of each interface may be different.
Currently, in order for an application program to support the routing requirements of an interface in a plurality of different implementation scenarios, a main method used is a factory mode.
In the related art, a simple factory mode or an abstract factory mode is adopted, implementation classes of all interfaces are registered one by one, corresponding key value pairs are stored in MAP (mapping relation), and the purpose of routing the interfaces to the corresponding implementation classes is achieved by routing the corresponding values in MAP through keys corresponding to the interfaces by using the mapping relation in MAP. However, in this manner, for each implementation class of each interface, the implementation class of the interface needs to be registered first to route to the implementation class, so that the operation process is complex.
Disclosure of Invention
The application provides a routing method, a routing device, electronic equipment and a storage medium of interfaces, which are used for solving the problems that in the related art, for each implementation class of each interface, the implementation class of the interface is registered first and then can be routed to the implementation class, and the operation process is complex.
In a first aspect, an embodiment of the present application provides a method for routing an interface, including:
obtaining an implementation request of a target interface, wherein the implementation request of the target interface comprises a routing entry;
Acquiring a routing rule corresponding to the target interface;
obtaining the realization class of each interface of the service providing system;
and determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rule and the routing entry so as to finish the implementation of the target interface through the target implementation class.
Optionally, the obtaining the implementation class of each interface of the service providing system includes:
scanning an annotation identifier in a service providing system, wherein the annotation identifier indicates an implementation class in the service providing system, and the annotation identifier comprises routing parameters of the implementation class;
and obtaining the implementation class corresponding to the annotation identifier.
Optionally, the determining, according to the routing rule and the routing parameter, a target implementation class corresponding to the target interface in the implementation classes, so as to complete implementation of the interface through the target implementation class includes:
and matching the routing parameters in the implementation classes according to the routing rules to obtain the target implementation classes.
Optionally, the matching the routing parameters in the implementation class participating in the routing according to the routing rule to obtain the target implementation class includes:
Judging whether the routing parameters participated in the routing meet the complete matching rule in the routing rule or not;
if yes, taking the implementation class corresponding to the routing parameters meeting the complete matching rule as the target implementation class;
if not, the routing is matched with the routing parameters according to fuzzy matching rules in the routing rules, and the successfully matched implementation class is used as the target implementation class.
Optionally, the step of matching the routing entry with the routing parameter according to a fuzzy matching rule in the routing rule, and taking a successfully matched implementation class as the target implementation class includes:
establishing a parameter entry linked list according to the route parameter entry, wherein each node in the parameter entry linked list stores one parameter entry parameter in the route parameter entry;
acquiring a pointer set, wherein the pointer set comprises an initial number of pointers, each pointer points to different parameter, and the initial number is smaller than the number of parameter;
and executing the following first fuzzy matching process on the parameter pointed by the pointer group according to the fuzzy matching rule:
matching the parameter pointed by the pointer group with the routing parameter in the implementation class;
If the matching is successful, taking the matched implementation class as the target implementation class;
if the matching is unsuccessful, moving the positions of the pointers in the pointer group, and executing the fuzzy matching process again until the pointer group finishes the combination traversal of the initial number of the parameter entries in the routing parameter entries;
and if the target implementation class is not determined after the traversal is finished, subtracting one from the initial number, and continuing to execute the first fuzzy matching process on the parameter pointed by the subtracted pointer group until the target implementation class is determined.
Optionally, the step of matching the routing entry with the routing parameter according to a fuzzy matching rule in the routing rule, and taking an implementation class corresponding to a matching result as the target implementation class includes:
grouping the parameter input according to a grouping rule to obtain at least one parameter input group, wherein each parameter input group comprises at least one parameter input;
according to the sequence that the number of the parameter entering in the parameter entering group is at least more, the following second fuzzy matching process is executed on the parameter entering group:
matching the parameter of the parameter group with the route parameter;
If the matching is successful, taking the realization class corresponding to the routing parameter which is successfully matched as the target realization class;
and if the matching is unsuccessful, executing the second fuzzy matching process on the next group of the parameter entering group until the matching is successful.
Optionally, the establishing an entry list according to the routing entry, where each node in the entry list stores one entry parameter in the routing entry, includes:
acquiring the priority of each parameter in the routing parameter;
and sequentially storing the parameter entering parameters in nodes of the parameter entering linked list according to the priority.
Optionally, the matching the parameter pointed by the pointer set with a routing parameter in the implementation class includes:
matching the parameter entering parameters with the priority pointed by the pointer group as the initial quantity before with the routing parameters in the implementation class;
the moving the position of the pointer in the pointer group includes:
and moving the pointer position according to the priority of the parameter, wherein the sum of the levels of the priorities of the parameter before the pointer moves is higher than or equal to the sum of the levels of the priorities of the parameter after the pointer moves, and the higher the priority of the parameter is, the higher the level of the priority is.
Optionally, the determining, according to the routing rule and the routing parameter, a target implementation class corresponding to the target interface in the implementation classes, so as to complete implementation of the target interface through the target implementation class, further includes:
generating a hash value of the routing entry;
taking the hash value as the hash value of the target implementation class;
and storing the hash value of the target implementation class into a cache.
Optionally, the implementation request of the target interface further includes function information; after the routing rule corresponding to the target interface is obtained, the method further comprises:
acquiring a routing version library, wherein the routing version library comprises versions of interfaces of the service providing system, and different versions of the interfaces correspondingly realize different functional information;
determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rule and the routing entry, so as to complete the implementation of the target interface through the target implementation class, including:
acquiring a route interface version corresponding to the target interface from the route version library according to the function information;
and determining a target implementation class corresponding to the target interface in the implementation classes according to the route interface version, the route rule and the route entry so as to finish the implementation of the target interface through the target implementation class.
Optionally, the obtaining the routing rule corresponding to the target interface includes:
generating a routing center corresponding to the target interface;
and obtaining the routing rule in the routing center.
Optionally, the routing entry includes: at least one set of sub-routing entries including routing keywords and routing keyword values.
In a second aspect, an embodiment of the present application provides a routing device for an interface, including:
the first acquisition module is used for acquiring an implementation request of a target interface, wherein the implementation request of the target interface comprises a routing entry;
the second acquisition module is used for acquiring the routing rule corresponding to the target interface;
the third acquisition module is used for acquiring the implementation class of each interface of the service providing system;
and the implementation module is used for determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rule and the routing parameter, so as to complete the implementation of the target interface through the target implementation class.
Optionally, the method further comprises:
the generation module is used for generating the hash value of the routing entry and taking the hash value as the hash value of the target implementation class;
and the storage module is used for storing the hash value of the target implementation class into a cache.
In a third aspect, an embodiment of the present application provides an electronic device, including: the device comprises a processor, a memory and a communication bus, wherein the processor and the memory are communicated with each other through the communication bus;
the memory is used for storing a computer program;
the processor is configured to execute the program stored in the memory, and implement the method for routing an interface according to the first aspect.
In a fourth aspect, an embodiment of the present application provides a computer readable storage medium storing a computer program, where the computer program when executed by a processor implements the method for routing an interface according to the first aspect.
Compared with the prior art, the technical scheme provided by the embodiment of the application has the following advantages: the method for routing the interfaces provided by the embodiment of the application acquires the implementation class of each interface in the service providing system, does not need to register the implementation class of the interface in advance, acquires the routing rule corresponding to the target interface after acquiring the implementation request of the target interface, so as to determine the target implementation class corresponding to the target interface in all the implementation classes of the service providing system through the routing rule and the routing entry, complete the implementation of the target interface through the target implementation class, does not need to register the interfaces and the implementation classes correspondingly, can determine the implementation class corresponding to the target interface only through the routing entry and the routing rule, and simplifies the operation of the routing process.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
In order to more clearly illustrate the embodiments of the application or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, and it will be obvious to a person skilled in the art that other drawings can be obtained from these drawings without inventive effort.
FIG. 1 is a flow chart of a method for routing an interface according to an embodiment of the present application;
fig. 2 is a flowchart of a method for routing an interface according to another embodiment of the present application;
FIG. 3 is a flowchart of a method for routing an interface according to another embodiment of the present application;
FIG. 4 is a schematic diagram of a joining list in a routing method of an interface according to an embodiment of the present application;
FIG. 5 is a schematic diagram illustrating a pointer set pointing to an entry list in a routing method of an interface according to an embodiment of the present application;
FIG. 6 is a schematic diagram illustrating a pointer set pointing to an entry list in a routing method of an interface according to another embodiment of the present application;
FIG. 7 is a schematic diagram illustrating a pointer set pointing to an entry list in a routing method of an interface according to another embodiment of the present application;
FIG. 8 is a schematic diagram illustrating a pointer set pointing to an entry list in a routing method of an interface according to another embodiment of the present application;
FIG. 9 is a flowchart of a method for routing an interface according to another embodiment of the present application;
FIG. 10 is a flowchart of a method for routing an interface according to another embodiment of the present application;
fig. 11 is a block diagram of a routing device of an interface according to an embodiment of the present application;
fig. 12 is a block diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Before describing embodiments of the present application in further detail, the terms and terminology involved in the embodiments of the present application will be described, and the terms and terminology involved in the embodiments of the present application will be used in the following explanation.
Route (routing): refers to the network-wide process of determining the end-to-end path of a packet as it travels from source to destination.
Factory mode: factory Pattern (Factory Pattern) is one of the most commonly used design patterns in Java. This type of design pattern belongs to the creation type pattern, which provides an optimal way of creating objects.
In factory mode, we do not expose creation logic to clients when creating objects, and point to newly created objects by using a common interface.
Iterator mode: an Iterator schema (Iterator) provides a way to sequentially access the various elements in an aggregate object without exposing the internal representation of the object.
Linked list: a linked list is a non-contiguous, non-sequential storage structure on physical storage elements, and the logical order of data elements is achieved by the order of pointer links in the linked list. The linked list is made up of a series of nodes (each element in the linked list is called a node) that can be dynamically generated at runtime. Each node comprises two parts: one is a data field storing a data element and the other is a pointer field storing the address of the next node. The operation is complicated compared to the linear table sequential structure. Since it is not necessary to store in order, the linked list can reach the complexity of O (1) at the time of insertion much faster than another linear table order table, but the time of O (n) is needed to find a node or access a node of a specific number, and the corresponding time complexity of the linear table and the order table are O (log n) and O (1), respectively.
Hash table: a Hash table (also called a Hash table) is a data structure that is directly accessed according to a Key value (Key value). That is, it accesses the record by mapping the key value to a location in the table to speed up the lookup. This mapping function is called a hash function and the array in which the records are stored is called a hash table.
The embodiment of the application provides an interface routing method which can be applied to any type of electronic equipment, such as a terminal and a server. As shown in fig. 1, the routing method of the interface includes:
step 101, obtaining an implementation request of a target interface, wherein the implementation request of the target interface comprises a routing entry.
In some embodiments, the implementation request of the target interface includes interface information, where the interface information specifies an interface that needs to be routed to the implementation class as a target interface, and in addition, the implementation request includes a routing entry, where the routing entry may be a single routing entry or multiple routing entries. It should be noted that, for the same implementation class, multiple interfaces may be implemented at the same time, and for the same interface, multiple implementation classes may also be routed, so when the routing entry is a multi-routing entry, any one of the multi-routing entries may be used to route to the target implementation class.
Specifically, the routing entry includes: at least one set of sub-routing entries including routing keys and values of the routing keys. It will be appreciated that when there are a plurality of sub-route entries, each sub-route entry also includes a packet number of the sub-route entry. When the routing entry is a multi-routing entry (i.e. the routing entry includes a plurality of sub-routing entries), the routing keywords in each sub-routing parameter and the values of the routing keywords are respectively matched with the routing parameters in the implementation class according to the packet number.
Step 102, obtaining a routing rule corresponding to the target interface.
In some embodiments, after determining the target interface, a routing center corresponding to the target interface is generated, and a routing rule in the routing center is obtained.
Specifically, the routing center is obtained by inheriting the routing framework, and the routing center can realize all functions in the routing framework. And injecting the generated routing center into the target interface so that the target interface is routed to the target implementation class through the routing rule of the routing center.
In general, the process of the routing center inheriting the routing framework can be completed through null implementation, and can be realized through a method of rewriting the parent class when special requirements exist.
Step 103, obtaining the realization class of each interface of the service providing system.
In some embodiments, the service providing system includes multiple interfaces of implementation classes, and annotation identifiers are added in each implementation class, and routing parameters of the implementation class are injected in the annotation identifiers. When the implementation class is acquired, all the implementation classes in the service providing system can be acquired by scanning the annotation identification in the service providing system, all the implementation classes are summarized, and the summarized implementation classes are stored in the corresponding routing containers.
Further, when the implementation class is acquired, the annotation identifier in the service providing system may be acquired in the routing container, or rescanned to obtain all the implementation classes.
Specifically, annotation identification within the system may be provided through a spring bean scanning service.
Wherein the routing parameters of the implementation class injected in the annotation identifier comprise a common routing parameter and a set of routing parameters.
Specifically, when the routing parameter is a common routing parameter, the specific different implementation types of the interface can be designated as the currently implemented routing parameter through the annotation identifier. Therefore, the routing can be realized when the routing parameter meets the set common routing parameter.
In addition, since there are different routing rules in different scenarios, it is possible that the current class implements multiple interfaces at the same time, and the routing rule of each interface is different, so the annotation identifier in the implementation class is set to the routing parameter set. Thus, when the routing entry meets any one packet in the routing parameter set, the routing can be realized.
Further, in the routing parameter for a certain implementation class, a "x" may also be used to characterize that the routing parameter may be matched by any value, so that any incoming parameters in the looped version of the current version are routed to the implementation class.
And 104, determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rules and the routing parameters so as to complete the implementation of the target interface through the target implementation class.
In some embodiments, after all implementation classes in the service providing system are acquired, the routing parameters in the implementation classes can be routed into and matched according to the routing rule, so as to obtain the target implementation class.
Specifically, the routing rules include a complete matching rule and a fuzzy matching rule, and the routing parameters of the routing in the participation implementation class are matched according to the routing rules to obtain the target implementation class, and referring to fig. 2, the method includes:
Step 201, determining whether the routing parameters of the routing participation meet the complete matching rule in the routing rules, if yes, executing step 202, and if no, executing step 203.
In some embodiments, the perfect matching rule is to determine whether the routing parameters of the routing participation are completely consistent, and determine whether the routing parameters of the routing participation are completely consistent when the routing parameters are common routing parameters, and determine whether any packet in the routing parameter set of the routing participation is completely consistent when the routing parameters are routing parameter sets.
Step 202, taking the implementation class corresponding to the routing parameters meeting the complete matching rule as a target implementation class.
In some embodiments, when the routing participation routing parameter satisfies the complete matching rule, the implementation class corresponding to the routing parameter is used as the target implementation class, so that the implementation of the target interface is completed through the target implementation class.
Step 203, the routing is entered into the participation routing parameters, matching is carried out according to fuzzy matching rules in the routing rules, and the successfully matched implementation class is taken as a target implementation class.
In some embodiments, after determining that the routing parameters of the routing participation are not completely consistent, matching the routing parameters of the routing participation according to a fuzzy matching rule, thereby determining the target implementation class after the matching is successful.
There are various ways to implement step 203, for example, the target implementation class may be determined in the following two ways.
First, the method includes the steps of matching the routing entry participation routing parameters according to fuzzy matching rules in the routing rules, and taking the successfully matched implementation class as a target implementation class, and referring to fig. 3, the method includes the following steps:
step 301, an entry list is established according to the route entry, and each node in the entry list stores one entry parameter in the route entry.
In some embodiments, when the route entry is uploaded, the provider sets the priority of each entry parameter in the route entry, and when the entry list is established, the priority of each entry parameter in the route entry is acquired first, and the entry parameters are sequentially stored in the nodes of the entry list according to the priority.
Specifically, the priorities of the parameter entering parameters are ordered, and the parameter entering parameters are stored in the nodes according to the sequence of the priorities, so that a parameter entering linked list is obtained.
Referring to fig. 4, taking the number of parameters as 4 as an example, the priority of each parameter is shown in fig. 4.
Step 302, acquiring a pointer set, where the pointer set includes an initial number of pointers, each pointer points to a different parameter, and the initial number is smaller than the number of parameters.
In some embodiments, referring to fig. 5, the parameter is 4, and the initial number is 3. The pointer group comprises 3 pointers and points to different parameter entering parameters respectively.
And executing the following first fuzzy matching process according to the fuzzy matching rule by pointing the pointer group to the parameter.
Step 303, matching the parameter pointed by the pointer group with the routing parameter in the implementation class; if the matching is successful, step 304 is performed, and if the matching is not successful, step 305 is performed.
In some embodiments, the priority of the parameters is different, so that each pointer in the pointer set points to the initial number of parameters before starting. Based on the above related embodiments, the parameter entry pointing to the top-of-priority rank 3.
Step 304, taking the matched implementation class as a target implementation class.
Based on the above related embodiment, the number of pointers is 3, the number of parameter entries is 4, and the parameter entries with priority ordered to be the first 3 are matched with the routing parameters in the implementation class. Specifically, the number of the parameter entering parameters is generally consistent with the number of the parameters in the routing parameters, and when the routing parameters entering the participant in the routing cannot be completely matched, part of the parameter entering parameters in the routing parameter entering the routing parameter are matched with the routing parameters, so that the target implementation class is determined. When the three parameter entering parameters are matched with the routing parameters, if the parameter matching with the routing parameters is successful, the successfully matched implementation class is taken as a target implementation class.
Step 305, moving the positions of the pointers in the pointer group, and executing the fuzzy matching process again until the pointer group traverses the combination of the initial number of parameter entries in the routing parameter entries.
Based on the above related embodiments, since the number of pointers is 3 and the number of parameter sets is 4, the parameter sets of parameter sets pointed by the pointer set are totally 4, and after the pointer moves in the pointer set, the parameter sets pointed by the pointer are matched with the routing parameters in the implementation class.
Furthermore, as the parameter entering parameters have priority, in the pointer moving process, the parameter entering parameters with high priority are pointed first, so that the matched implementation class is more accurate. Specifically, the pointer position is moved according to the priority of the parameter, wherein the sum of the levels of the priorities of the parameter before the pointer is moved is higher than or equal to the sum of the levels of the priorities of the parameter after the pointer is moved, and the higher the priority of the parameter is, the higher the level of the priority is.
Before the pointer moves, the sum of the levels of the priorities of the parameters to be input pointed by the pointer is 6, referring to fig. 6, after the pointer moves for the first time, the sum of the levels of the priorities of the parameters to be input pointed by the pointer is 6, referring to fig. 7, and after the pointer moves for the second time, the sum of the levels of the priorities of the parameters to be input pointed by the pointer is 5.
Further, after the parameter group of the parameter is traversed by the pointer group with the initial number of pointers, the target implementation class is not determined yet, the initial number is reduced by one, and the parameter group pointed by the reduced pointer group continues to execute the first fuzzy matching process until the target implementation class is determined.
Referring to fig. 8, after subtracting one from the initial number, the number of pointers is 2, still pointing first to the first two parameter entries with high priority, and sequentially moving the pointers.
Second, the routing-in participation routing parameters are matched according to fuzzy matching rules in the routing rules, and the implementation class corresponding to the matching result is used as a target implementation class, and referring to fig. 9, the method includes:
step 901, grouping the parameter according to a grouping rule to obtain at least one parameter group, wherein each parameter group comprises at least one parameter.
In some embodiments, taking 4 parameter entries as an example, routing entries are grouped according to the number of parameters, so as to obtain 4 parameter entries with 3 parameter entries, 6 parameter entries with 2 parameter entries, and 4 parameter entries with 1 parameter entry.
The following second fuzzy matching process is performed on the parameter entering group according to the sequence that the number of parameter entering parameters in the parameter entering group is at least more than the number of parameter entering parameters:
Step 902, matching the parameter of the parameter group with the route parameter, if the matching is successful, executing step 903, and if the matching is not successful, executing step 904.
Based on the above related embodiments, the matching is performed on the input parameter of 3 input parameter groups, after the matching of all the input parameter groups of 3 input parameter groups is completed, the matching is performed on the input parameter group of 2 input parameter groups, and so on until the matching is successful.
And 903, taking the implementation class corresponding to the successfully matched routing parameter as a target implementation class.
Step 904, a second fuzzy matching process is performed on the next set of the input parameter sets until the matching is successful.
Further, determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rule and the routing parameter, so as to complete implementation of the target interface through the target implementation class, and further comprising:
generating a hash value of the routing entry; taking the hash value as the hash value of the target implementation class; the hash value of the target implementation class is stored in a cache.
In some embodiments, for the same routing entry, under the condition that the routing rule is not changed, the corresponding routing implementation results are consistent, so that the speed of routing to the implementation class is increased. Further, the hash value of the target implementation class is stored in the cache, and the implementation class is not required to be searched each time by introducing a cache mechanism. The cache is stored by adopting a hash table, and the target implementation class is determined by searching in the hash table according to the hash value. Further, in order to avoid the conflict of the calculated hash value, in this embodiment, after the hash value is calculated, it is verified whether the hash value is already present in the hash table, if not, the hash value is stored corresponding to the target implementation class, and if so, it is verified whether the hash value is calculated correctly.
In an actual scenario, after receiving an implementation request of a front-end target interface, an interface version number to be referred to by a current thread is also obtained based on rule mapping. The version number serves as a parameter for all routes under the current thread. In actual use, the interface version number is not necessarily equal to the version number of the route. Because interfaces specifying version numbers are combined differently for different implementation classes. For example: when the target interface is the next interface, it is assumed that two steps are implemented:
the first step: and checking logic, namely checking that a unified entry is arranged, and routing is needed.
And a second step of: the order is also provided with a unified entrance, and routing is needed.
The externally exposed interface version is assumed to be 2.0, but the implementation class for check interface routing may be 1.0, while the implementation class for ordering routing may be 2.0.
In order to solve the problem of interface layer combination, the realization request of the target interface also comprises function information; after obtaining the routing rule corresponding to the target interface, the method further comprises:
and acquiring a routing version library, wherein the routing version library comprises versions of interfaces of the service providing system, and the versions of different interfaces correspondingly realize different functional information.
In some embodiments, when the target interface implements different functions, the versions of their corresponding interfaces are also different. The versions of all interfaces are stored in the routing version library, so that when routing to the target implementation class, the version of the routing interface corresponding to the target interface is determined from the routing version library. It should be noted that, when routing to the implementation class through the routing version, each implementation class includes a corresponding interface version.
Specifically, a routing version corresponding to a target interface is obtained from a routing version library according to the function information; and determining a target implementation class corresponding to the target interface in the implementation classes according to the routing version, the routing rule and the routing entry so as to complete the implementation of the target interface through the target implementation class.
In some embodiments, referring to fig. 10, after an implementation request of a target interface is obtained, according to functional information in the implementation request, a routing version corresponding to the target interface is obtained from a routing version library first, and in a routing process, other interfaces may be called to complete routing to a target implementation class, so that multiple routing versions corresponding to the target interface may exist. When the route is to the target realization class, the route version and the route parameter are matched with the interface version and the route parameter in the realization class through the route rule, so as to determine the target realization class.
In the application, a unified routing framework is arranged. After receiving the realization request of the target interface, the target interface inherits the routing framework and generates a routing center, so that the target is routed to a specific target realization class according to the routing rule in the routing center. And the unified code management is facilitated by analyzing the specification through the unified project routing framework. In addition, the application can obtain the realization class of all interfaces by directly using the spring bean scanning mechanism without manually registering the interfaces. In addition, the method solves the problems that different manufacturers adapt to different interface versions, multi-version support is realized, and unified version management is realized, so that the personalized requirements of different clients are met. Flexible route rules are adopted, and when the routes cannot be completely matched, the routes are strictly matched and fuzzy matching is performed according to the priority of the route entry parameters. In addition, multiple groups of routes are realized by carrying out custom annotation on the realization class, one interface supports multiple routing rules, and can support expression rule routing.
In the application, the routing framework realizes perfect integration with spring, can facilitate decoupling of service modules, facilitate modularization and management, and support value expressions, group routes, routing priorities and the like corresponding to multi-rule routes. In order to further support the multi-version function, the concept of a routing version library is introduced, so that the interface version management is facilitated. The method supports the selection parameters (fuzzy matching of the routing parameters), and the robustness of the routing framework is greatly improved by using the parameter priority function.
Based on the same conception, the embodiment of the present application provides a testing device, and the specific implementation of the device may be referred to the description of the embodiment of the method, and the repetition is omitted, as shown in fig. 11, where the device mainly includes:
the first obtaining module 1101 is configured to obtain an implementation request of a target interface, where the implementation request of the target interface includes a routing entry;
the second obtaining module 1102 is configured to obtain a routing rule corresponding to the target interface;
a third obtaining module 1103, configured to obtain implementation classes of interfaces of the service providing system;
and the implementation module 1104 is configured to determine, according to the routing rule and the routing parameter, a target implementation class corresponding to the target interface in the implementation classes, so as to complete implementation of the target interface through the target implementation class.
Based on the same concept, the embodiment of the application also provides an electronic device, as shown in fig. 12, where the electronic device mainly includes: a processor 1201, a memory 1202 and a communication bus 1203, wherein the processor 1201 and the memory 1202 perform communication with each other via the communication bus 1203. The memory 1202 stores therein a program executable by the processor 1201, and the processor 1201 executes the program stored in the memory 1202 to implement the following steps:
Obtaining an implementation request of a target interface, wherein the implementation request of the target interface comprises a routing entry;
obtaining a routing rule corresponding to a target interface;
obtaining the realization class of each interface of the service providing system;
and determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rules and the routing parameters so as to complete the implementation of the target interface through the target implementation class.
The communication bus 1203 mentioned in the above-mentioned electronic device may be a peripheral component interconnect standard (Peripheral Component Interconnect, abbreviated to PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, abbreviated to EISA) bus, or the like. The communication bus 1203 may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, only one thick line is shown in fig. 12, but not only one bus or one type of bus.
The memory 1202 may include random access memory (Random Access Memory, simply RAM) or may include non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor 1201.
The processor 1201 may be a general-purpose processor including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), a digital signal processor (Digital Signal Processing, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a Field programmable gate array (Field-Programmable Gate Array, FPGA), or other programmable logic device, discrete gate or transistor logic device, or discrete hardware components.
In a further embodiment of the present application, there is also provided a computer-readable storage medium having stored therein a computer program which, when run on a computer, causes the computer to perform the method of routing an interface described in the above embodiments.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, 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 instructions. When the computer instructions are loaded and executed on a computer, the processes or functions described in accordance with embodiments of the present application are produced in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions 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, by a wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, microwave, etc.) means from one website, computer, server, or data center to another. The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape, etc.), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk), etc.
It should be noted that in this document, relational terms such as "first" and "second" and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The foregoing is only a specific embodiment of the invention to enable those skilled in the art to understand or practice the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (15)

1. A method for routing an interface, comprising:
obtaining an implementation request of a target interface, wherein the implementation request of the target interface comprises a routing entry;
acquiring a routing rule corresponding to the target interface;
obtaining the realization class of each interface of the service providing system; adding annotation identifiers in each implementation class of the service providing interface, wherein the annotation identifiers comprise routing parameters of the corresponding implementation class, and the routing parameters comprise one or more of a routing parameter group and a common routing parameter; the routing parameter set is used for indicating the same implementation class corresponding to a plurality of routing rules; the common routing parameters are used for indicating the implementation class corresponding to the single routing rule;
and determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rule and the routing entry so as to finish the implementation of the target interface through the target implementation class.
2. The method for routing interfaces according to claim 1, wherein the obtaining the implementation class of each interface of the service providing system comprises:
scanning annotation identification in a service providing system;
and obtaining the implementation class corresponding to the annotation identifier.
3. The method for routing an interface according to claim 1 or 2, wherein determining, according to the routing rule and the routing parameter, a target implementation class corresponding to the target interface in the implementation classes, so as to complete implementation of the interface through the target implementation class, includes:
and matching the routing parameters in the implementation classes according to the routing rules to obtain the target implementation classes.
4. The method for routing an interface according to claim 3, wherein said matching the routing parameters of the routing into the implementation class according to the routing rule to obtain the target implementation class includes:
judging whether the routing parameters participated in the routing meet the complete matching rule in the routing rule or not;
if yes, taking the implementation class corresponding to the routing parameters meeting the complete matching rule as the target implementation class;
if not, the routing is matched with the routing parameters according to fuzzy matching rules in the routing rules, and the successfully matched implementation class is used as the target implementation class.
5. The method for routing an interface according to claim 4, wherein said step of matching the routing parameters according to fuzzy matching rules among the routing rules, using a successfully matched implementation class as the target implementation class, includes:
Establishing a parameter entry linked list according to the route parameter entry, wherein each node in the parameter entry linked list stores one parameter entry parameter in the route parameter entry;
acquiring a pointer set, wherein the pointer set comprises an initial number of pointers, each pointer points to different parameter, and the initial number is smaller than the number of parameter;
and executing the following first fuzzy matching process on the parameter pointed by the pointer group according to the fuzzy matching rule:
matching the parameter pointed by the pointer group with the routing parameter in the implementation class;
if the matching is successful, taking the matched implementation class as the target implementation class;
if the matching is unsuccessful, moving the positions of the pointers in the pointer group, and executing the fuzzy matching process again until the pointer group finishes the combination traversal of the initial number of the parameter entries in the routing parameter entries;
and if the target implementation class is not determined after the traversal is finished, subtracting one from the initial number, and continuing to execute the first fuzzy matching process on the parameter pointed by the subtracted pointer group until the target implementation class is determined.
6. The method for routing an interface according to claim 4, wherein said matching the routing parameters according to fuzzy matching rules in the routing rules, and taking an implementation class corresponding to the matching result as the target implementation class, includes:
Grouping the parameter input according to a grouping rule to obtain at least one parameter input group, wherein each parameter input group comprises at least one parameter input;
according to the sequence that the number of the parameter entering in the parameter entering group is at least more, the following second fuzzy matching process is executed on the parameter entering group:
matching the parameter of the parameter group with the route parameter;
if the matching is successful, taking the realization class corresponding to the routing parameter which is successfully matched as the target realization class;
and if the matching is unsuccessful, executing the second fuzzy matching process on the next group of the parameter entering group until the matching is successful.
7. The method according to claim 5, wherein the establishing an entry list according to the route entries, each node in the entry list storing one entry parameter in the route entries comprises:
acquiring the priority of each parameter in the routing parameter;
and sequentially storing the parameter entering parameters in nodes of the parameter entering linked list according to the priority.
8. The method of claim 7, wherein said matching the parameter of the pointer set to the parameter of the implementation class comprises:
Matching the parameter entering parameters with the priority pointed by the pointer group as the initial quantity before with the routing parameters in the implementation class;
the moving the position of the pointer in the pointer group includes:
and moving the pointer position according to the priority of the parameter, wherein the sum of the levels of the priorities of the parameter before the pointer moves is higher than or equal to the sum of the levels of the priorities of the parameter after the pointer moves, and the higher the priority of the parameter is, the higher the level of the priority is.
9. The method for routing an interface according to claim 1, wherein determining, according to the routing rule and the routing parameter, a target implementation class corresponding to the target interface in the implementation classes, so as to complete implementation of the target interface by the target implementation class, further comprises:
generating a hash value of the routing entry;
taking the hash value as the hash value of the target implementation class;
and storing the hash value of the target implementation class into a cache.
10. The method for routing an interface according to claim 1, wherein the request for implementing the target interface further includes function information; after the routing rule corresponding to the target interface is obtained, the method further comprises:
Acquiring a routing version library, wherein the routing version library comprises versions of interfaces of the service providing system, and different versions of the interfaces correspondingly realize different functional information;
determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rule and the routing entry, so as to complete the implementation of the target interface through the target implementation class, including:
acquiring a route interface version corresponding to the target interface from the route version library according to the function information;
and determining a target implementation class corresponding to the target interface in the implementation classes according to the route interface version, the route rule and the route entry so as to finish the implementation of the target interface through the target implementation class.
11. The method for routing an interface according to claim 1, wherein the obtaining the routing rule corresponding to the target interface includes:
generating a routing center corresponding to the target interface;
and obtaining the routing rule in the routing center.
12. The method of routing an interface according to any one of claims 1, 2, 4-11, wherein the routing parameters include: at least one set of sub-routing entries including routing keys and values of the routing keys.
13. A routing apparatus for an interface, comprising:
the first acquisition module is used for acquiring an implementation request of a target interface, wherein the implementation request of the target interface comprises a routing entry;
the second acquisition module is used for acquiring the routing rule corresponding to the target interface;
the third acquisition module is used for acquiring the implementation class of each interface of the service providing system; adding annotation identifiers in each implementation class of the service providing interface, wherein the annotation identifiers comprise routing parameters of the corresponding implementation class, and the routing parameters comprise one or more of a routing parameter group and a common routing parameter; the routing parameter set is used for indicating the same implementation class corresponding to a plurality of routing rules; the common routing parameters are used for indicating the implementation class corresponding to the single routing rule;
and the implementation module is used for determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rule and the routing parameter, so as to complete the implementation of the target interface through the target implementation class.
14. An electronic device, comprising: the device comprises a processor, a memory and a communication bus, wherein the processor and the memory are communicated with each other through the communication bus;
The memory is used for storing a computer program;
the processor being configured to execute a program stored in the memory to implement the method of routing an interface according to any one of claims 1-12.
15. A computer readable storage medium storing a computer program, wherein the computer program when executed by a processor implements the method of routing an interface according to any one of claims 1-12.
CN202110231182.3A 2021-03-02 2021-03-02 Interface routing method and device, electronic equipment and storage medium Active CN114996181B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110231182.3A CN114996181B (en) 2021-03-02 2021-03-02 Interface routing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110231182.3A CN114996181B (en) 2021-03-02 2021-03-02 Interface routing method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN114996181A CN114996181A (en) 2022-09-02
CN114996181B true CN114996181B (en) 2023-09-26

Family

ID=83018059

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110231182.3A Active CN114996181B (en) 2021-03-02 2021-03-02 Interface routing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114996181B (en)

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6651248B1 (en) * 2000-09-01 2003-11-18 International Business Machines Corporation Method and apparatus for efficient interface method dispatch
US6813770B1 (en) * 2000-04-21 2004-11-02 Sun Microsystems, Inc. Abstract syntax notation to interface definition language converter framework for network management
US7949999B1 (en) * 2007-08-07 2011-05-24 Amazon Technologies, Inc. Providing support for multiple interface access to software services
CN106874176A (en) * 2015-12-14 2017-06-20 阿里巴巴集团控股有限公司 Intelligent test method and device
CN107171959A (en) * 2017-04-20 2017-09-15 深圳中兴网信科技有限公司 Dynamic routing method and dynamic routing system based on SOA
CN107707614A (en) * 2017-08-16 2018-02-16 深圳市丰巢科技有限公司 App route implementation methods, equipment and the storage medium of agreement are jumped based on system
CN107918562A (en) * 2016-10-11 2018-04-17 北京京东尚科信息技术有限公司 A kind of unified interface management method and system
CN109032569A (en) * 2018-08-02 2018-12-18 山东浪潮通软信息科技有限公司 A kind of RESTful service method for automatically releasing based on attribute tags
CN109766148A (en) * 2017-11-08 2019-05-17 北京京东尚科信息技术有限公司 Method and apparatus for Processing Interface method call
CN111580797A (en) * 2020-05-13 2020-08-25 上海创蓝文化传播有限公司 Dynamic routing grouping method based on dubbo and spring framework
CN111752625A (en) * 2020-06-23 2020-10-09 京东数字科技控股有限公司 Method and device for interface mock
CN111831365A (en) * 2020-07-29 2020-10-27 中国平安财产保险股份有限公司 Interface route forwarding method, system, computer equipment and readable storage medium

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6813770B1 (en) * 2000-04-21 2004-11-02 Sun Microsystems, Inc. Abstract syntax notation to interface definition language converter framework for network management
US6651248B1 (en) * 2000-09-01 2003-11-18 International Business Machines Corporation Method and apparatus for efficient interface method dispatch
US7949999B1 (en) * 2007-08-07 2011-05-24 Amazon Technologies, Inc. Providing support for multiple interface access to software services
CN106874176A (en) * 2015-12-14 2017-06-20 阿里巴巴集团控股有限公司 Intelligent test method and device
CN107918562A (en) * 2016-10-11 2018-04-17 北京京东尚科信息技术有限公司 A kind of unified interface management method and system
CN107171959A (en) * 2017-04-20 2017-09-15 深圳中兴网信科技有限公司 Dynamic routing method and dynamic routing system based on SOA
CN107707614A (en) * 2017-08-16 2018-02-16 深圳市丰巢科技有限公司 App route implementation methods, equipment and the storage medium of agreement are jumped based on system
CN109766148A (en) * 2017-11-08 2019-05-17 北京京东尚科信息技术有限公司 Method and apparatus for Processing Interface method call
CN109032569A (en) * 2018-08-02 2018-12-18 山东浪潮通软信息科技有限公司 A kind of RESTful service method for automatically releasing based on attribute tags
CN111580797A (en) * 2020-05-13 2020-08-25 上海创蓝文化传播有限公司 Dynamic routing grouping method based on dubbo and spring framework
CN111752625A (en) * 2020-06-23 2020-10-09 京东数字科技控股有限公司 Method and device for interface mock
CN111831365A (en) * 2020-07-29 2020-10-27 中国平安财产保险股份有限公司 Interface route forwarding method, system, computer equipment and readable storage medium

Also Published As

Publication number Publication date
CN114996181A (en) 2022-09-02

Similar Documents

Publication Publication Date Title
US10042746B2 (en) Callpath finder
CN112148509A (en) Data processing method, device, server and computer readable storage medium
US9043757B2 (en) Identifying differences between source codes of different versions of a software when each source code is organized using incorporated files
CN108008936B (en) Data processing method and device and electronic equipment
CN108595342B (en) Unit testing method and device
US20110113019A1 (en) Concurrent Database Access by Production and Prototype Applications
CN114064690A (en) Data processing method and device
CN110764748B (en) Code calling method, device, terminal and storage medium
CN110659019B (en) Parameter verification method, device and server
CN115292197A (en) Software testing method and device, electronic equipment and storage medium
CN114996181B (en) Interface routing method and device, electronic equipment and storage medium
CN111078773B (en) Data processing method and device
CN111259619A (en) Control method and device for configuration object, storage medium and verification platform
CN110795646A (en) Request processing method and device, electronic equipment and computer-readable storage medium
CN112395339B (en) Intersystem data admission verification method, device, computer equipment and storage medium
CN111736848B (en) Packet conflict positioning method, device, electronic equipment and readable storage medium
CN114329090A (en) Path reference searching method and device, electronic equipment and storage medium
CN109635175B (en) Page data splicing method and device, readable storage medium and electronic equipment
CN112540820A (en) User interface updating method and device and electronic equipment
CN111405486B (en) Trajectory analysis method and device, electronic equipment and storage medium
CN112433943A (en) Method, device, equipment and medium for detecting environment variable based on abstract syntax tree
CN110297651A (en) The update method and device of the common variable of protocol interface
CN111045724A (en) Query method and device for call chain information and readable storage medium
CN114997111B (en) Service processing method, device, computer equipment and storage medium
CN115496129B (en) Software matching method and device

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