CN114996181A - 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
CN114996181A
CN114996181A CN202110231182.3A CN202110231182A CN114996181A CN 114996181 A CN114996181 A CN 114996181A CN 202110231182 A CN202110231182 A CN 202110231182A CN 114996181 A CN114996181 A CN 114996181A
Authority
CN
China
Prior art keywords
routing
parameter
target
interface
implementation class
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110231182.3A
Other languages
Chinese (zh)
Other versions
CN114996181B (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

Images

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 routing 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: acquiring a realization request of a target interface, wherein the realization request of the target interface comprises route entry parameters; acquiring a routing rule corresponding to a target interface; acquiring the implementation class of each interface of a 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 and the device solve 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 be routed 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 routing method and apparatus for an interface, an electronic device, and a storage medium.
Background
Different customers have different implementations of the same function for the platform project and the floor project. In a specific application, different routing rules may exist in different implementation scenarios, for example, a current class implements multiple interfaces simultaneously, and the routing rule of each interface may be different.
At present, in order to enable an application program to support the routing requirement of an interface in a plurality of different implementation scenarios, a factory mode is mainly used.
In the related art, a simple factory model or an abstract factory model is adopted, implementation classes of all interfaces are registered one by one, corresponding key value pairs are stored in a MAP (mapping relationship), and the mapping relationship in the MAP is utilized to route the interfaces to the corresponding values in the MAP through the keys corresponding to the interfaces, so that the purpose of routing the interfaces to the corresponding implementation classes is achieved. However, in this way, for each implementation class of each interface, the implementation class of the interface needs to be registered first to be routed to the implementation class, and the operation process is complicated.
Disclosure of Invention
The application provides an interface routing method, an interface routing device, an electronic device and a storage medium, 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 needs to be registered first, routing can be performed to the implementation class, and the operation process is complex.
In a first aspect, an embodiment of the present application provides a routing method for an interface, including:
acquiring an implementation request of a target interface, wherein the implementation request of the target interface comprises route entry parameters;
acquiring a routing rule corresponding to the target interface;
acquiring the implementation class of each interface of a 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 entry parameters, so as to complete the implementation of the target interface through the target implementation class.
Optionally, the obtaining of 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 a routing parameter of the implementation class;
and acquiring the implementation class corresponding to the annotation identifier.
Optionally, the determining, according to the routing rule and the routing entry parameter, a target implementation class corresponding to the target interface in the implementation class, so as to complete implementation of the interface through the target implementation class includes:
and matching the routing parameters participating in the implementation class according to the routing rule to obtain the target implementation class.
Optionally, the entering the route into the routing parameter participating in the implementation class and matching according to the routing rule to obtain the target implementation class includes:
judging whether the route entry participation routing parameter meets a complete matching rule in the routing rules;
if so, taking the implementation class corresponding to the routing parameter meeting the complete matching rule as the target implementation class;
if not, the route is participated in the route parameters, matching is carried out according to fuzzy matching rules in the route rules, and the successfully matched implementation class is taken as the target implementation class.
Optionally, the participating of the route entry in the routing parameter is performed with matching according to a fuzzy matching rule in the routing rule, and the implementation class successfully matched is taken as the target implementation class, including:
establishing a parameter entering list according to the route parameter, wherein each node in the parameter entering list stores one parameter entering the route parameter;
acquiring a pointer group, wherein the pointer group comprises an initial number of pointers, each pointer points to a different parameter of the parameter, and the initial number is less than the number of the parameters of the parameter;
executing the following first fuzzy matching process on the parameter of the reference 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, the matched implementation class is taken as the target implementation class;
if the matching is not successful, moving the position of the pointer in the pointer group, and executing the fuzzy matching process again until the pointer group traverses the combination of the initial number of the parameter entries in the route entry;
and if the target implementation class is not determined after traversal is finished, reducing the initial quantity by one, and continuing to execute the first fuzzy matching process on the parameter of the input parameter pointed by the pointer group after the reduction by one until the target implementation class is determined.
Optionally, the participating of the route entry in the routing parameter is performed with matching according to a fuzzy matching rule in the routing rule, and an implementation class corresponding to a matching result is taken as the target implementation class, including:
grouping the parameter to obtain at least one parameter group according to a grouping rule, wherein each parameter group comprises at least one parameter;
performing the following second fuzzy matching process on the participating group according to the sequence of at least more than one number of participating parameters in the participating group:
matching the parameter of the participating group with the routing parameter;
if the matching is successful, taking the implementation class corresponding to the successfully matched routing parameter as the target implementation class;
and if the matching is not successful, executing the second fuzzy matching process on the next group of the participating groups until the matching is successful.
Optionally, the establishing a parameter entering list according to the route parameter entering, where each node in the parameter entering list stores one parameter entering the route parameter entering list includes:
acquiring the priority of each parameter of the route access;
and sequentially storing the parameter of the priority.
Optionally, the matching the parameter of the entry pointed by the pointer group with the routing parameter in the implementation class includes:
matching the entry parameters with the priority pointed by the pointer group as the initial number 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 priority of the parameter before the pointer is moved is higher than or equal to the sum of the levels of the priority 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.
Optionally, the determining, according to the routing rule and the routing entry parameter, a target implementation class corresponding to the target interface in the implementation class, so that after the target implementation class completes implementation of the target interface, further includes:
generating a hash value of the route entry parameter;
taking the hash value as the hash value of the target implementation class;
and storing the hash value of the target implementation class in a cache.
Optionally, the implementation request of the target interface further includes function information; after the obtaining of the routing rule corresponding to the target interface, the method further includes:
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 rules and the routing entry parameters, so as to complete the implementation of the target interface through the target implementation class, including:
acquiring a routing interface version corresponding to the target interface from the routing version library according to the function information;
and determining a target implementation class corresponding to the target interface in the implementation class according to the routing interface version, the routing rule and the routing entry parameter, so as to complete the implementation of the target interface through the target implementation class.
Optionally, the obtaining of the routing rule corresponding to the target interface includes:
generating a routing center corresponding to the target interface;
obtaining routing rules in the routing center.
Optionally, the route entry includes: and at least one group of sub-route access parameters, wherein the sub-route access parameters comprise route keywords and route keyword values.
In a second aspect, an embodiment of the present application provides a routing apparatus for an interface, including:
the first acquisition module is used for acquiring a realization request of a target interface, wherein the realization request of the target interface comprises route entry;
the second obtaining module is used for obtaining the routing rule corresponding to the target interface;
the third acquisition module is used for acquiring the implementation classes of all interfaces 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 class according to the routing rule and the routing entry parameter so as to complete the implementation of the target interface through the target implementation class.
Optionally, the method further includes:
a generating module, configured to generate a hash value of the route entry parameter, and use the hash value as a 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 system 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 for storing a computer program;
the processor is configured to execute the program stored in the memory, and implement the interface routing method according to the first aspect.
In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program 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 routing method of the interface provided by the embodiment of the application obtains the implementation classes of each interface in the service providing system, does not need to register the implementation classes of the interfaces in advance, and obtains the routing rule corresponding to the target interface after obtaining the implementation request of the target interface.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without inventive exercise.
Fig. 1 is a flowchart of a routing method for an interface according to an embodiment of the present application;
fig. 2 is a flowchart of a routing method for an interface according to another embodiment of the present application;
fig. 3 is a flowchart of a routing method for an interface according to another embodiment of the present application;
fig. 4 is a schematic diagram of an entry parameter table in a routing method of an interface according to an embodiment of the present application;
fig. 5 is a schematic diagram illustrating a pointer group pointing to an entry list in a routing method for an interface according to an embodiment of the present application;
fig. 6 is a schematic diagram illustrating a pointer group pointing to an entry list in a routing method for an interface according to another embodiment of the present application;
fig. 7 is a schematic diagram illustrating a pointer group pointing to an entry list in a routing method for an interface according to another embodiment of the present application;
fig. 8 is a schematic diagram illustrating a pointer group 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
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Before further detailed description of the embodiments of the present invention, terms and expressions referred to in the embodiments of the present invention are described, and the terms and expressions referred to in the embodiments of the present invention are applicable to the following explanations.
Routing (routing): refers to the network-wide process of determining an end-to-end path as a packet travels from a source to a destination.
Factory mode: factory Pattern (Factory Pattern) is one of the most common design patterns in Java. This type of design schema belongs to the creation type schema, which provides an optimal way to create objects.
In factory mode, we do not expose the creation logic to the client when creating objects and point to newly created objects by using a common interface.
Iterator mode: iterator mode (Iterator), provides a way to sequentially access various elements in an aggregate object without exposing an internal representation of the object.
Chain table: a linked list is a non-continuous, non-sequential storage structure on a physical storage unit, and the logical order of data elements is realized by the order of pointer links in the linked list. A linked list is composed of a series of nodes (each element in the linked list is called a node), which can be dynamically generated at runtime. Each node comprises two parts: one is a data field that stores the data element and the other is a pointer field that stores the address of the next node. Compared with a linear table sequential structure, the operation is complex. Since it is not necessary to store in order, the linked list can be inserted with O (1) complexity, which is much faster than another linear list order list, but it takes O (n) time to find a node or access a node with a specific number, and the time complexity of the linear list and the order list is O (log n) and O (1), respectively.
A hash table: a Hash table (also called Hash table) is a data structure that is directly accessed from a Key value (Key value). That is, it accesses the record by mapping the key value to a location in the table to speed the lookup. This mapping function is called a hash function and the array of stored records is called a hash table.
An embodiment of the present application provides a routing method for an interface, which may be applied to any form of electronic devices, such as a terminal and a server. As shown in fig. 1, the interface routing method includes:
step 101, obtaining a target interface implementation request, where the target interface implementation request includes a route entry parameter.
In some embodiments, the implementation request of the target interface includes interface information, where the interface information specifies that an interface that needs to be routed to the implementation class is the target interface, and in addition, the implementation request includes a route entry, where the route entry may be a single route entry or a multiple route entry. It should be noted that, for the same implementation class, multiple interfaces may be implemented simultaneously, and for the same interface, multiple implementation classes may also be routed, so that when the route entry parameter is the multiple route entry parameter, the route entry parameter may be routed to the target implementation class through any one of the multiple route entry parameters.
Specifically, the route entry includes: at least one set of sub-route entries comprising a route key and a value of the route key. It is to be understood that, when there are a plurality of sub-route entry references, each sub-route entry reference further includes a packet number of the sub-route entry reference. When the route entry parameter is a multi-route entry parameter (that is, the route entry parameter includes a plurality of sub-route entry parameters), the routing key words and the values of the routing key words in the sub-route parameters are respectively matched with the routing parameters in the implementation class according to the packet numbers.
And 102, acquiring a routing rule corresponding to the target interface.
In some embodiments, after the target interface is determined, 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 a routing framework, and the routing center can implement 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.
Generally, the process of inheriting the routing framework by the routing center can be completed by null implementation, and when special requirements exist, the process can be realized by a method of rewriting a parent class.
And 103, acquiring the implementation class of each interface of the service providing system.
In some embodiments, the service providing system includes a plurality of implementation classes of interfaces, and an annotation identifier is added to each implementation class, and the annotation identifier is injected with a routing parameter of the implementation class. When the implementation classes are obtained, all the implementation classes in the service providing system can be obtained by scanning the annotation identifiers in the service providing system, all the implementation classes are collected, and the collected implementation classes are stored in the corresponding routing containers.
Further, when the implementation class is obtained, the annotation identifier in the service providing system may be obtained in the routing container or rescanned to obtain all the implementation classes.
Specifically, annotation identification within the system may be provided by a spring bean scanning service.
The routing parameters of the implementation class injected in the annotation identifier include common routing parameters and routing parameter groups.
Specifically, when the routing parameter is a common routing parameter, different specific implementation classes of the interface can be specified as the currently implemented routing parameter through the annotation identifier. Therefore, the routing can be realized by participating in the routing to meet the set common routing parameters.
In addition, because there are different routing rules in different scenarios, it is possible that multiple interfaces are simultaneously implemented in the current class, and the routing rules of each interface are different, so the annotation identifier in the implementation class is set as a routing parameter set. Therefore, routing can be realized by participating in any packet in the route meeting the routing parameter set.
Further, for a routing parameter of an implementation class, a value may be used to characterize that the routing parameter may be matched by any value, so that any entry parameter in the enclosed version in the current version is routed to the implementation class.
And step 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 the implementation classes in the service providing system are obtained, the routing parameters participating in the implementation classes can be routed, and matching is performed according to the routing rules to obtain the target implementation classes.
Specifically, the routing rule includes a complete matching rule and a fuzzy matching rule, the routing parameter of the route participating in the implementation class is matched according to the routing rule to obtain the target implementation class, and with reference to fig. 2, the method includes:
step 201, determining whether the route entry participation route parameter meets a complete matching rule in the route rules, if yes, executing step 202, and if no, executing step 203.
In some embodiments, the complete matching rule is to determine whether the route entry participation routing parameters are completely consistent, determine whether the route entry participation ordinary routing parameters are completely consistent when the routing parameters are ordinary routing parameters, and determine whether any packet in the route entry participation routing parameter set is completely consistent when the routing parameters are routing parameter sets.
Step 202, the implementation class corresponding to the routing parameter satisfying the complete matching rule is taken as the target implementation class.
In some embodiments, when the route entry participation route parameter satisfies the complete matching rule, the implementation class corresponding to the route parameter is used as the target implementation class, so that the target interface is implemented by the target implementation class.
And 203, matching the route entry participation route parameters according to a fuzzy matching rule in the route rule, and taking the successfully matched implementation class as a target implementation class.
In some embodiments, after determining that the route entry participation route parameters are not completely consistent, matching the route entry participation route parameters according to a fuzzy matching rule, so as to determine the target implementation class after successful matching.
There are various ways to implement step 203, for example, the target implementation class may be determined in the following two ways.
First, matching a route entry participation route parameter according to a fuzzy matching rule in a route rule, and taking a successfully matched implementation class as a target implementation class, referring to fig. 3, including:
step 301, establishing a parameter entering list according to the route parameter entering, wherein each node in the parameter entering list stores one parameter entering the route parameter entering.
In some embodiments, when the route entry parameter is uploaded, the provider sets the priority of each entry parameter in the route entry parameter, and when the entry parameter list is established, the priority of each entry parameter in the route entry parameter is acquired first, and the entry parameter is stored in the node of the entry parameter list in sequence according to the priority.
Specifically, the priorities of the parameters to be entered are sorted, and the parameters to be entered are stored in the nodes according to the priority order of the priorities, so as to obtain a list of the entered parameters.
Referring to fig. 4, taking the number of the parameter entries as 4 as an example, the priority of each parameter entry is as shown in fig. 4.
Step 302, a pointer group is obtained, where the pointer group includes an initial number of pointers, each pointer points to a different parameter, and the initial number is smaller than the number of the parameters.
In some embodiments, referring to fig. 5, the number of the reference parameters is 4, and the initial number is 3. The pointer group includes 3 pointers, and the pointers point to different parameter entries respectively.
And executing the following first fuzzy matching process according to the fuzzy matching rule by using the parameter of the pointer pointed by the pointer group.
Step 303, matching the parameter of the entry pointed by the pointer group with the routing parameter in the implementation class; if the matching is successful, go to step 304, and if the matching is not successful, go to step 305.
In some embodiments, since the priority of the parameter to be entered is different, each pointer in the pointer set points to the previous initial number of parameters to be entered at the beginning. Based on the above-described related embodiment, the parameter of entry pointing to the top 3 of the priority ranking.
And step 304, taking the matched implementation class as a target implementation class.
Based on the above-described related embodiment, the number of pointers is 3, the number of entry parameters is 4, and the entry parameters with the priority ranking of top 3 are matched with the routing parameters in the implementation class. Specifically, the number of the entry parameters is generally consistent with the number of the parameters in the routing parameters, and when the routing entry parameters cannot be completely matched, part of the entry parameters in the routing entry entries are matched with the routing parameters, so that the target implementation class is determined. And when the three parameter-entering parameters are matched with the routing parameters, if the three parameter-entering parameters are successfully matched with the parameters in the routing parameters, taking the successfully matched implementation class as a target implementation class.
And 305, moving the position of the pointer in the pointer group, and executing the fuzzy matching process again until the pointer group finishes traversing the combination of the initial number of the parameter of the route parameter.
Based on the above related embodiment, since the number of the pointers is 3 and the number of the parameter to be included is 4, 4 parameter sets of the parameter to be included to which the pointer group points are provided, and after the pointers in the pointer group move, the parameter to be included to which the pointers newly point is matched with the routing parameter in the implementation class.
Furthermore, since the parameter to be entered has priority, the parameter to be entered with higher priority is pointed to first in the moving process of the pointer, so that the matching implementation class is more accurate. Specifically, the pointer position is moved according to the priority of the parameter, wherein the sum of the priority levels of the parameter before the pointer is moved is higher than or equal to the sum of the priority levels of the parameter after the pointer is moved, and the higher the priority level of the parameter is, the larger the priority level of the parameter is.
Before the pointer moves, the sum of the levels of the priority levels of the parameter to be referred to by the pointer is 6, referring to fig. 6, after the pointer moves for the first time, the sum of the levels of the priority levels of the parameter to be referred to by the pointer is 6, referring to fig. 7, after the pointer moves for the second time, the sum of the levels of the priority levels of the parameter to be referred to by the pointer is 5.
Further, after the pointer group traverses the parameter group of the parameter to be entered with the initial number of pointers, the target implementation class is not determined yet, the initial number is reduced by one, and the parameter to be entered to which the pointer group after the reduction points continues to execute the first fuzzy matching process until the target implementation class is determined.
Referring to fig. 8, after the initial number is reduced by one, the number of pointers is 2, and the pointers are moved sequentially while pointing to the first two parameter entries having high priority.
Second, matching the route entry participation route parameter according to the fuzzy matching rule in the route rule, and taking the implementation class corresponding to the matching result as the target implementation class, referring to fig. 9, including:
and 901, grouping the access parameter according to a grouping rule to obtain at least one access group, wherein each access group comprises at least one access parameter.
In some embodiments, taking 4 entry parameters as an example, the route entry parameters are grouped according to the number of parameters, and 4 entry groups with 3 entry parameters, 6 entry groups with 2 entry parameters, and 4 entry groups with 1 entry parameter are obtained.
And performing the following second fuzzy matching process on the participating group according to the sequence of at least the number of the participating parameters in the participating group:
and 902, matching the parameter of the participating group with the routing parameter, if the matching is successful, executing 903, and if the matching is not successful, executing 904.
Based on the related embodiment, the 3 participating groups with the participating parameters are matched, after the matching of all the 3 participating groups with the participating parameters is finished, the 2 participating groups with the participating parameters are matched, 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.
And 904, executing a second fuzzy matching process on the next group of input parameters until the matching is successful.
Further, determining a target implementation class corresponding to the target interface in the implementation classes according to the routing rules and the routing entry parameters, so as to complete the implementation of the target interface through the target implementation class, further including:
generating a hash value of the route entry parameter; taking the hash value as the hash value of the target implementation class; and storing the hash value of the target implementation class in a cache.
In some embodiments, for the same route entry, in the case that the routing rule is not changed, the corresponding route implementation results are consistent, and therefore, the speed of routing to the implementation class is increased. Further, the hash value of the target implementation class is stored in a cache, and by introducing a cache mechanism, the implementation class does not need to be searched each time. The cache is stored by adopting a hash table, and is searched in the hash table according to the hash value, so that the target implementation class is determined. Furthermore, in order to avoid the collision of the calculated hash values, in this embodiment, after the hash value is calculated, it is verified whether the hash value already exists in the hash table, if not, the hash value is stored in correspondence with the target implementation class, and if so, it is checked whether the hash value is calculated correctly.
In an actual scenario, after receiving a request for implementing a front-end target interface, the method further obtains an interface version number to be referenced by a current thread based on rule mapping. The version number is used as a parameter of all routes under the current thread. In practical applications, the interface version number is not necessarily equal to the version number of the route. Because the interfaces with specified version numbers have different combinations for different implementation classes. For example: when the target interface is a next interface, the realization of two steps is supposed:
the first step is as follows: and checking logic, wherein a uniform inlet is checked, and routing is needed.
The second step is that: ordering, ordering also has a uniform entrance, and routing is needed.
The exposed interface version is assumed to be 2.0, but the implementation class routed to for the check interface may be 1.0, while the implementation class routed to next order may be 2.0.
In order to solve the problem of interface layer combination, the implementation request of the target interface also comprises function information; after obtaining the routing rule corresponding to the target interface, the method further includes:
and acquiring a routing version library, wherein the routing version library comprises versions of each interface of the service providing system, and the versions of different interfaces correspondingly realize different functional information.
In some embodiments, when the target interfaces implement different functions, the versions of their corresponding interfaces are different. The routing version library stores versions of all interfaces, so that when routing to a target implementation class, a routing interface version corresponding to a target interface needs to be determined from the routing version library. It should be noted that, when routing is performed to the implementation classes through the routing versions, each implementation class includes a corresponding interface version.
Specifically, a routing version corresponding to the 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 rules and the routing parameters so as to complete the implementation of the target interface through the target implementation class.
In some embodiments, referring to fig. 10, after the implementation request of the target interface is obtained, according to the function information in the implementation request, the routing version corresponding to the target interface is obtained from the routing version library first, and since other interfaces may also be called in the routing process to complete routing to the target implementation class, there may be a plurality of routing versions corresponding to the target interface. 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, thereby determining the target realization class.
In the application, a unified routing framework is arranged. After receiving the implementation request of the target interface, the target interface inherits the routing framework to generate a routing center, so that the routing is routed to a specific target implementation class according to the routing rule in the routing center. And the unified code management is facilitated through the unified project routing framework analysis specification. In addition, the implementation of interfaces does not need to be manually registered, and the implementation classes of all the interfaces can be obtained by directly using a spring bean scanning mechanism. In addition, different manufacturers are matched with different interface versions to realize, multi-version support is achieved, version management is unified, and personalized requirements of different customers are met. And flexible routing rules are adopted, the routing is strictly matched and fuzzy matched, and when the routing cannot be completely matched, fuzzy matching is carried out according to the priority of the routing entry parameters. In addition, multiple groups of routing are realized by performing custom annotation on the implementation classes, and one interface supports multiple routing rules and can support expression rule routing.
In the application, the routing framework is perfectly integrated with spring, meanwhile, service module decoupling can be facilitated, modularization management is facilitated, multi-rule routing, value expressions corresponding to routing keys, group routing, routing priority and the like are supported. In order to further support multi-version functions, the concept of a routing version library is introduced, and interface version management is facilitated. The selection parameters (routing parameter fuzzy matching) are supported, and the use of the parameter priority function greatly improves the robustness of the routing framework.
Based on the same concept, embodiments of the present application provide a testing apparatus, and specific implementation of the apparatus may refer to descriptions in the method embodiment section, and repeated descriptions are omitted, as shown in fig. 11, the apparatus 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 route entry;
a second obtaining module 1102, 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;
the implementation module 1104 is configured to determine, according to the routing rule and the routing entry parameter, a target implementation class corresponding to the target interface in the implementation classes, so as to implement the target interface through the target implementation class.
Based on the same concept, an embodiment of the present application further provides an electronic device, as shown in fig. 12, the electronic device mainly includes: a processor 1201, a memory 1202, and a communication bus 1203, wherein the processor 1201 and the memory 1202 communicate with each other via the communication bus 1203. Wherein, the memory 1202 stores programs executable by the processor 1201, and the processor 1201 executes the programs stored in the memory 1202 to realize the following steps:
acquiring a realization request of a target interface, wherein the realization request of the target interface comprises route entry parameters;
acquiring a routing rule corresponding to a target interface;
acquiring the implementation class of each interface of a 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 electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus 1203 may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 12, but that does not indicate only one bus or one type of bus.
The Memory 1202 may include a Random Access Memory (RAM) or a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. Alternatively, the memory may be at least one memory device located remotely from the processor 1201.
The Processor 1201 may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components.
In yet another 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 execute the method for routing an interface described in the above embodiment.
In the above embodiments, the implementation may be wholly or partially realized 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 loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the application to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored on a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wire (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wirelessly (e.g., infrared, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that includes one or more of the available media. The available media may be magnetic media (e.g., floppy disks, hard disks, tapes, etc.), optical media (e.g., DVDs), or semiconductor media (e.g., solid state drives), among others.
It is noted that, in this document, relational terms such as "first" and "second," and the like, may be 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. Also, 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 an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The foregoing are merely exemplary embodiments of the present invention, which enable those skilled in the art to understand or practice the present 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:
acquiring an implementation request of a target interface, wherein the implementation request of the target interface comprises route entry parameters;
acquiring a routing rule corresponding to the target interface;
acquiring the implementation class of each interface of a 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 entry parameters, so as to complete the implementation of the target interface through the target implementation class.
2. The interface routing method according to claim 1, wherein 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 a routing parameter of the implementation class;
and acquiring the implementation class corresponding to the annotation identifier.
3. The interface routing method according to claim 1 or 2, wherein the determining, according to the routing rule and the route entry, a target implementation class corresponding to the target interface in the implementation class, so as to complete implementation of the interface through the target implementation class includes:
and matching the routing parameters participating in the implementation class according to the routing rule to obtain the target implementation class.
4. The interface routing method according to claim 3, wherein the obtaining the target implementation class by matching the routing parameters participating in the implementation class according to the routing rule includes:
judging whether the route entry participation routing parameter meets a complete matching rule in the routing rules;
if so, taking the implementation class corresponding to the routing parameter meeting the complete matching rule as the target implementation class;
if not, the route is participated in the route parameters, matching is carried out according to fuzzy matching rules in the route rules, and the successfully matched implementation class is taken as the target implementation class.
5. The interface routing method according to claim 4, wherein the participating of the route entry in the routing parameter is matched according to a fuzzy matching rule in the routing rule, and an implementation class successfully matched is taken as the target implementation class, including:
establishing a parameter-entering chain table according to the route parameter-entering, wherein each node in the parameter-entering chain table stores one parameter-entering parameter in the route parameter-entering chain table;
obtaining a pointer set, wherein the pointer set comprises an initial number of pointers, each pointer points to a different parameter of the pointer;
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, the matched implementation class is taken as the target implementation class;
if the matching is not successful, moving the position of the pointer in the pointer group, and executing the fuzzy matching process again until the pointer group completes the traversing of the combination of the initial number of the parameter of the route parameter;
and if the target implementation class is not determined after traversal is finished, reducing the initial quantity by one, and continuing to execute the first fuzzy matching process on the parameter of the input parameter pointed by the pointer group after the reduction by one until the target implementation class is determined.
6. The interface routing method according to claim 4, wherein the participating of the route entry in the routing parameter is matched according to a fuzzy matching rule in the routing rule, and an implementation class corresponding to a matching result is taken as the target implementation class, including:
grouping the parameter to obtain at least one parameter group according to a grouping rule, wherein each parameter group comprises at least one parameter to be entered;
performing the following second fuzzy matching process on the participating group according to the sequence of at least more than one number of participating parameters in the participating group:
matching the parameter of the participating group with the routing parameter;
if the matching is successful, taking the implementation class corresponding to the successfully matched routing parameter as the target implementation class;
and if the matching is not successful, executing the second fuzzy matching process on the next group of the participating groups until the matching is successful.
7. The interface routing method of claim 5, wherein the establishing a join list according to the route join parameters, each node in the join list storing one join parameter of the route join parameters comprises:
acquiring the priority of each parameter of the route access;
and sequentially storing the parameter of the priority.
8. The interface routing method according to claim 7, wherein the matching the entry parameter pointed to by the pointer group with the routing parameter in the implementation class includes:
matching the entry parameters with the priority pointed by the pointer group as the initial number 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 priority of the parameter before the pointer is moved is higher than or equal to the sum of the levels of the priority 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.
9. The interface routing method according to claim 1, wherein the determining, according to the routing rule and the route entry, a target implementation class corresponding to the target interface in the implementation classes, so that after the target implementation class completes implementation of the target interface, further includes:
generating a hash value of the route entry;
taking the hash value as the hash value of the target implementation class;
and storing the hash value of the target implementation class in a cache.
10. The interface routing method according to claim 1, wherein the implementation request of the target interface further includes function information; after the obtaining of the routing rule corresponding to the target interface, the method further includes:
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 rules and the routing entry parameters, so as to complete the implementation of the target interface through the target implementation class, including:
acquiring a routing interface version corresponding to the target interface from the routing version library according to the function information;
and determining a target implementation class corresponding to the target interface in the implementation class according to the route interface version, the route rule and the route entry parameter, so as to complete the implementation of the target interface through the target implementation class.
11. The interface routing method 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;
obtaining routing rules in the routing center.
12. The interface routing method according to any one of claims 1, 2, 4-11, wherein the route entry includes: at least one set of sub-route entries comprising a routing key and a value of the routing key.
13. A routing apparatus for an interface, comprising:
the first acquisition module is used for acquiring a realization request of a target interface, wherein the realization request of the target interface comprises route entry;
the second obtaining module is used for obtaining the routing rule corresponding to the target interface;
the third acquisition module is used for acquiring the implementation classes of all interfaces 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 class according to the routing rule and the routing entry parameter so as to complete the implementation of the target interface through the target implementation class.
14. An electronic device, comprising: the system 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 for storing a computer program;
the processor, configured to execute the program stored in the memory, and implement the routing method of the interface according to any one of claims 1 to 12.
15. A computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the method for 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 true CN114996181A (en) 2022-09-02
CN114996181B 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

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
MARYDON: "springboot同一请求入口,根据不同入参用不同实体类接收&调用不同接口实现类", pages 1 - 9 *

Also Published As

Publication number Publication date
CN114996181B (en) 2023-09-26

Similar Documents

Publication Publication Date Title
US10042746B2 (en) Callpath finder
JP6031203B2 (en) API version checking based on query schema
JP6200505B2 (en) Graph query logic
CN109062794B (en) Method and device for determining software evaluation result and electronic equipment
US11650905B2 (en) Testing source code changes
US8392467B1 (en) Directing searches on tree data structures
CN107665171A (en) Automatic regression test method and device
CN108008936B (en) Data processing method and device and electronic equipment
CN110764775A (en) Application program integration method and device, storage medium and server
WO2023241529A1 (en) Vulnerability information processing method, service apparatus and vulnerability detection module
CN115292197A (en) Software testing method and device, electronic equipment and storage medium
CN110659019B (en) Parameter verification method, device and server
US9740589B2 (en) Lifting of bounded liveness counterexamples to concrete liveness counterexamples
CN113158627A (en) Code complexity detection method and device, storage medium and electronic equipment
Dincturk Model-based crawling-an approach to design efficient crawling strategies for rich internet applications
CN114996181B (en) Interface routing method and device, electronic equipment and storage medium
CN110795646A (en) Request processing method and device, electronic equipment and computer-readable storage medium
CN111736848B (en) Packet conflict positioning method, device, electronic equipment and readable storage medium
JP7111967B2 (en) Program verification program, program verification method and program verification device
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
US20080082471A1 (en) Resolve Trace Minimization
US20230394141A1 (en) Indexing Software Packages and Detecting Malicious or Potentially Harmful Code using API-call N-Grams
CN117520136A (en) Function test method, device and equipment of application program and readable storage medium
CN116661792A (en) Code checking method, device, equipment, storage medium and program product

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