Service access method, system, computer device and storage medium
Through the collaborative work of the service management center and the gateway, the problem that services in a container environment are difficult to access from the outside is solved, the flexibility and dynamic routing of service access are achieved, and the external access capability of the service is improved.
Patent Information
- Application Number
- CN202111627331.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-12-28
AI Technical Summary
In a container environment, services are difficult to access from the outside, resulting in limited access flexibility.
Obtain the interface registration request of the service instance through the service management center, store the interface information in the metadata of the service discovery center, and when the gateway receives the access request, match the target access path and metadata, and route the access request to the target instance to achieve External access to the service.
It improves the flexibility of service access, solves the problem that services are difficult to access externally in a container environment, and realizes dynamic routing and load balancing of service instances.
Smart Images

Figure CN114363403B
Abstract
Description
Technical Field
[0001] The present application relates to the field of software technology, and in particular to a service access method, system, device, computer equipment and storage medium. Background Art
[0002] With the development of software technology, service-oriented architecture has gradually become the mainstream technology for IT integration. Enterprise service bus is a key part of the infrastructure used when building solutions based on service-oriented architecture. It is a set of infrastructure functions implemented by middleware technology, providing basic services for more complex architectures.
[0003] In a general sense, an enterprise service bus can be seen as a mechanism for managing access to applications and services by providing a single, simple and consistent interface to end users through a network or form-based client front end and providing basic services for access.
[0004] Usually, in order to ensure the security of service access, services are generally deployed in a container environment. As a result, services in a container environment are difficult to access externally and are too limited. Summary of the invention
[0005] Based on this, it is necessary to provide a service access method, system, apparatus, computer device, storage medium and computer program product that can improve the flexibility of service access in response to the above technical problems.
[0006] In a first aspect, the present application provides a service access method. The method comprises:
[0007] The service management center obtains interface registration requests sent by multiple instances of the service, and obtains corresponding interface information of the multiple instances based on the interface registration requests; the interface information includes the corresponding access path of the instance; the multiple instances are deployed in containers;
[0008] For each instance of the multiple instances, the service management center stores the interface information corresponding to the instance in the metadata of the instance in the service discovery center to complete the interface registration;
[0009] After the gateway receives the access request for the service, confirming, through the gateway, the target access path specified by the access request;
[0010] The gateway matches the target access path with the access path in the target metadata; the target metadata is the metadata of the instance of the service in the service discovery center;
[0011] The gateway determines the interface information of the target instance corresponding to the matched access path;
[0012] The gateway routes the access request to the target instance of the service based on the interface information of the target instance to access the service.
[0013] In one embodiment, the method further comprises:
[0014] For any one of the multiple instances, perform the following processing:
[0015] The service management center determines whether any one of the instances subscribes to the online monitoring event;
[0016] If any one of the instances has not subscribed to the online monitoring event, the service management center subscribes the online monitoring event to the service discovery center for the any one of the instances;
[0017] The service discovery center monitors the online status of any one of the instances based on the subscribed online monitoring event;
[0018] After monitoring that the instance is in an online state, the service discovery center sends an online notification to the service management center.
[0019] In one embodiment, the online notification is sent by the service discovery center to the service management center when the service discovery center monitors that the instance is back online after being disconnected; the method further includes:
[0020] For any one of the multiple instances, perform the following processing:
[0021] The Internet Protocol address of any one of the instances and the interface information of any one of the instances are stored in a database of the service management center in a one-to-one correspondence;
[0022] After any one of the instances comes back online, the service management center restores the interface information corresponding to the Internet Protocol address in the database to the metadata of any one of the instances.
[0023] In one embodiment, the gateway matching the target access path with the access path in the target metadata includes:
[0024] The gateway traverses the target metadata and matches the target access path with the access path in the traversed metadata;
[0025] The method further comprises:
[0026] The gateway determines the instance to which the access path that meets the matching requirement belongs, and obtains an instance set;
[0027] A target instance is selected from the instance set according to a routing policy.
[0028] In one embodiment, the interface information of the target instance includes an access port and an access path corresponding to the target instance; the gateway routing the access request to the second target instance of the service to access the service includes:
[0029] The gateway routes the access request to the target instance according to the corresponding Internet Protocol address, access port and access path of the target instance to access the service.
[0030] In one embodiment, after the gateway receives the access request for the service, confirming, by the gateway, the target access path specified by the access request includes:
[0031] After the gateway receives the access request for the service, the gateway obtains the request address used to send the access request;
[0032] The gateway extracts the target access path from the request address. 7. The method according to any one of claims 1 to 6, wherein the target metadata is metadata of an online instance of the service in the service discovery center.
[0033] In a second aspect, the present application also provides a service access system. The system includes: a service management center and a gateway;
[0034] The service management center is used to obtain interface registration requests sent by multiple instances of a service, and obtain interface information corresponding to the multiple instances based on the interface registration requests; the interface information includes access paths corresponding to the instances; the multiple instances are deployed in containers; for each of the multiple instances, the interface information corresponding to the instance is stored in the metadata of the instance in the service discovery center to complete the interface registration;
[0035] The gateway is used to confirm the target access path specified in the access request for the service after receiving the access request; match the target access path with the access path in the target metadata; the target metadata is the metadata of the instance of the service in the service discovery center; determine the interface information of the target instance corresponding to the matched access path; and route the access request to the target instance of the service based on the interface information of the target instance to access the service.
[0036] In a third aspect, the present application provides a service access device. The device comprises:
[0037] An acquisition module, used to acquire interface registration requests sent by multiple instances of a service, and acquire corresponding interface information of the multiple instances based on the interface registration requests; the interface information includes an access path corresponding to the instance; the multiple instances are deployed in a container;
[0038] A storage module, used for storing, for each instance among the multiple instances, the interface information corresponding to the instance into the metadata of the instance to complete the interface registration;
[0039] A confirmation module, configured to confirm a target access path specified in the access request after receiving the access request for the service;
[0040] A matching module, used for matching the target access path with the access path in the target metadata; the target metadata is the metadata of the instance of the service;
[0041] The matching module is further used to determine the interface information of the target instance corresponding to the matched access path;
[0042] A routing module is used to route the access request to the target instance of the service based on the interface information of the target instance, so as to access the service.
[0043] In a fourth aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor executes the steps of the above service access method.
[0044] In a fifth aspect, the present application further provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and the computer program is executed by a processor to perform the steps of the above service access method.
[0045] In a sixth aspect, the present application further provides a computer program product, wherein the computer program product comprises a computer program, and the computer program is executed by a processor to perform the steps of the above service access method.
[0046] The above-mentioned service access method, system, device, computer equipment, storage medium and computer program product obtain interface registration requests sent by multiple instances of the service through a service management center, and obtain interface information corresponding to the multiple instances based on the interface registration request; the interface information includes the corresponding access path of the instance. The multiple instances are deployed in a container. For each of the multiple instances, the service management center stores the corresponding interface information of the instance in the metadata of the instance in the service discovery center to complete the interface registration. In this way, the instance can actively publish and store interface information through the interface registration request. After the gateway receives the access request for the service, the gateway confirms the target access path specified by the access request; matches the target access path with the access path in the target metadata; the target metadata is the metadata of the instance of the service in the service discovery center. Determine the interface information of the target instance corresponding to the matched access path; so that the gateway obtains the required interface information. The gateway routes the access request to the target instance of the service based on the interface information of the target instance to access the service. Therefore, an interface registration request is actively initiated through the service instance, and the service discovery center is enabled to store and manage the interface information through the service management center, so that the gateway can obtain the interface information of each instance, and then access the service instance based on the instance interface information, thereby solving the problem of the service being difficult to access externally and improving the flexibility of service access. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 An application environment diagram of a service access method in an embodiment;
[0048] Figure 2 A schematic diagram of a flow chart of a service access method in an embodiment;
[0049] Figure 3 A schematic diagram of a flow chart of a service access method in an embodiment;
[0050] Figure 4 A schematic diagram of a flow chart of a service access method in an embodiment;
[0051] Figure 5 A schematic diagram of a flow chart of a service access method in an embodiment;
[0052] Figure 6 A structural block diagram of a service access system in one embodiment;
[0053] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0055] The service access method provided in the present application can be implemented by a computer device, and the computer device can be implemented as at least one of a terminal and a server, wherein the terminal can be but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, as well as big data and artificial intelligence platforms.
[0056] For example, the service access method provided by this application can be applied to Figure 1 In the application environment shown. Among them, the service management center 110 communicates with the service discovery center 120 through the network, the gateway 130 communicates with the service discovery center 120 through the network, and the instance running device 140 where the instance is located communicates with the service management center 110, the service discovery center 120 and the gateway 130 through the network. Among them, the service management center 110, the service discovery center 120, the gateway 130 and the instance running device 140 can be implemented with independent servers or terminals or a server cluster composed of multiple servers. It can be understood that the instance running device 140 can run at least one instance of a service, and can also run at least one instance of different services at the same time, without limitation.
[0057] Multiple instances of the service in the instance running device 140 send interface registration requests to the service management center 110, and the service management center 110 obtains the interface registration request and obtains the corresponding interface information of the multiple instances based on the interface registration request; the interface information includes the corresponding access path of the instance, and the multiple instances are deployed in the container. For each of the multiple instances, the service management center 110 stores the corresponding interface information of the instance in the metadata of the instance in the service discovery center 120. After the gateway 130 receives the access request for the service, the gateway 130 confirms the target access path specified by the access request. The gateway 130 matches the target access path with the access path in the target metadata. Among them, the target metadata is the metadata of the instance of the service in the service discovery center 120. The gateway 130 determines the interface information of the target instance corresponding to the matched access path. The gateway 130 routes the access request to the target instance of the service (i.e., to the target instance of the service in the instance running device 140) based on the interface information of the target instance to access the service.
[0058] In one embodiment, the service management center, the service discovery center, and the gateway may constitute a service platform (such as a technical middle platform) for providing service access functions.
[0059] It is worth noting that the above-mentioned service management center, service discovery center and gateway do not constitute a limitation on the embodiments of the present application. In actual application scenarios, there may be other architectures to implement the solutions of the embodiments of the present application. For example, the service management center, service discovery center and gateway can be further split, and for another example, the service management center and service discovery center can be integrated into one.
[0060] In one embodiment, Figure 2 As shown, a service access method is provided. This embodiment uses the method applied to a service management center and a gateway as an example. It can be understood that the service management center and the gateway can be a terminal, a server, or a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0061] S202, the service management center obtains interface registration requests sent by multiple instances of the service, and obtains corresponding interface information of the multiple instances based on the interface registration requests; the interface information includes the access path corresponding to the instance, and the multiple instances are deployed in the container;.
[0062] Among them, an instance is an independent computing unit virtualized from computer resources, which is used to implement the functions of a service. Interface information is used to call the interface published by the service. The access path is the path used to access the service. The access path corresponding to the instance can be understood as the access path of the service to which the instance belongs. The service management center is a software program that can manage services.
[0063] In one embodiment, the access path of the service may include a short access path for the service. The short access path may be partial information in the request address for the service that can identify the service. It can be understood that the request address for the service is equivalent to a complete path information for accessing the service. In addition to the short access path that can identify the service, the request address may also include other information such as a domain name. The present application can only determine the short access path that can identify the service, and implement the solution of the present application based on the short access path.
[0064] Specifically, multiple instances of a service send interface registration requests to a service management center, and the service management center obtains the interface registration requests sent by the multiple instances of the service, and obtains the corresponding interface information of the multiple instances based on the interface registration requests; the interface information includes the corresponding access path of the instance for accessing the service to which the instance belongs. The above multiple instances can be all instances of the service or some instances of the service, and are deployed in containers.
[0065] In one embodiment, the service management center may be a target microservice that manages the service, and at least one instance of the target microservice receives the interface registration request sent by the instance of the service.
[0066] In one embodiment, the service may be an integration service that is developed using low-code based on camel, a rule-based routing and mediation engine.
[0067] In one embodiment, the access path may be generated by a Uniform Resource Identifier (URI).
[0068] In another embodiment, the access path may be generated by a Uniform Resource Locator (URL).
[0069] In one embodiment, the interface registration request carries the interface information. The service management center can obtain the interface information from the interface registration request.
[0070] In one embodiment, the interface registered through the interface registration request can be an http (Hyper Text Transfer Protocol) / soap (Simple Object Access Protocol) interface, but is not limited to this. When the interface registered by the instance is an http interface, the instance can be accessed using the http protocol, and when the interface registered by the instance is a soap interface, the instance can be accessed using the soap protocol. The process of registering an interface includes a process of storing and managing interface information. The process of accessing an instance using a registered interface can be understood as a process of using the communication protocol to which the registered interface belongs as the communication protocol for accessing the instance, and using the interface information to access the instance. After the interface is registered, the device accessing the service accesses the instance in accordance with the corresponding communication protocol, and does not need to pay attention to the entire content of the interface information, thereby improving the security, flexibility and standardization of accessing the instance, that is, improving the security, flexibility and standardization of accessing the service to which the instance belongs.
[0071] S204: For each instance among the multiple instances, the service management center stores the corresponding interface information of the instance into the metadata of the instance in the service discovery center.
[0072] The service discovery center is used to record the information of all services in the distributed system so that other services can quickly find these registered services. Metadata, also known as intermediary data or relay data, is data that describes data, mainly information that describes data attributes, and is used to support functions such as indicating storage locations, historical data, resource searches, and file records.
[0073] Specifically, for each instance in the multiple instances, the service management center communicates with the service discovery center and stores the corresponding interface information of the instance in the metadata of the instance in the service discovery center.
[0074] In one embodiment, the service management center subscribes to the online monitoring event for the instance from the service discovery center to obtain the instance online notification.
[0075] In one embodiment, when the service management center confirms through the service discovery center that the instance is disconnected and then back online, the interface information stored in the database is restored to the metadata of the instance in the service discovery center.
[0076] S206, after the gateway receives the access request for the service, the gateway confirms the target access path specified in the access request; matches the target access path with the access path in the target metadata; the target metadata is the metadata of the instance of the service in the service discovery center; determines the interface information of the target instance corresponding to the matched access path.
[0077] It will be appreciated that gateways can be used to protect, enhance and control access to services.
[0078] Specifically, the device accessing the service sends an access request to the gateway. After the gateway receives the access request, the gateway can obtain the target access path specified by the access request. The gateway obtains the metadata of the service instance from the service discovery center and confirms it as the target metadata. The gateway matches the target access path with the access path in the target metadata. If the match is successful, the gateway can obtain the interface information of the target instance corresponding to the matched access path from the target metadata. The successful match here can mean the same.
[0079] In one embodiment, the gateway determines the instance to which the access path that meets the matching requirement belongs, obtains an instance set, and identifies the target instance from the instance set according to the routing policy.
[0080] In one embodiment, the gateway obtains a request address used to send the access request, and obtains a target access path specified by the access request based on the request address.
[0081] S208: The gateway routes the access request to the target instance of the service based on the interface information of the target instance to access the service.
[0082] Specifically, the gateway routes the access request to the target instance of the service based on the interface information of the target instance, and accesses the target instance, that is, accesses the service to which the target instance belongs.
[0083] In one embodiment, the interface information includes a port and an access path, and the gateway accesses the target instance based on the Internet Protocol address, access port, and access path corresponding to the target instance.
[0084] In one embodiment, the method also includes: the service management center determines whether the instance is subscribed to the online monitoring event; if the instance is not subscribed to the online monitoring event, the service management center subscribes to the online monitoring event for the instance to the service discovery center; the service discovery center monitors the online status of the instance based on the subscribed online monitoring event; after the service discovery center monitors that the instance is in the online state, it sends an online notification to the service management center.
[0085] Among them, subscribing to the online monitoring event is used to let the service discovery center wait for the occurrence of the instance online event. When the instance online event occurs, the service discovery center notifies the subscriber that the instance is online.
[0086] Specifically, for each of the multiple instances of a service, the service management center determines whether the instance is subscribed to the online listening event. If the instance is not subscribed to the online listening event, the service management center subscribes to the online listening event of the instance from the service discovery center. The service discovery center monitors the online status of the instance based on the subscribed online listening event. After the instance goes online, the service discovery center monitors that the instance is in the online state and sends an online notification to the service management center. The online notification can be used to trigger the service management center to register an interface based on the instance and obtain the corresponding interface information of the instance.
[0087] In this embodiment, the service management center subscribes to the online monitoring event for the instance, so that when the instance goes online, the service discovery center can obtain the online notification and start the online processing flow for the instance. In this way, the service management center completes the online processing flow for the instance with the assistance of the service discovery center, thereby reducing repeated code development and maintenance, and reducing the computer resource overhead of the device where the service management center is located.
[0088] The above service access method obtains interface registration requests sent by multiple instances of the service through the service management center, and obtains interface information corresponding to the multiple instances based on the interface registration requests; the interface information includes the corresponding access path of the instance. The multiple instances are deployed in a container. For each of the multiple instances, the service management center stores the corresponding interface information of the instance in the metadata of the instance in the service discovery center to complete the interface registration. In this way, the instance can actively publish and store the interface information through the interface registration request. After the gateway receives the access request for the service, the gateway confirms the target access path specified by the access request; matches the target access path with the access path in the target metadata; the target metadata is the metadata of the instance of the service in the service discovery center. Determine the interface information of the target instance corresponding to the matched access path; so that the gateway obtains the required interface information. The gateway routes the access request to the target instance of the service based on the interface information of the target instance to access the service. Therefore, an interface registration request is actively initiated through the service instance, and the service discovery center is enabled to store and manage the interface information through the service management center, so that the gateway can obtain the interface information of each instance, and then access the service instance based on the instance interface information, thereby solving the problem of the service being difficult to access externally and improving the flexibility of service access.
[0089] In one embodiment, it also includes: the service management center stores the Internet Protocol address of the instance and the interface information of the instance in a one-to-one correspondence in the database of the service management center; when the service discovery center monitors that the instance is back online after being lost, it sends an online notification to the service management center; based on the online notification, the service management center restores the interface information corresponding to the Internet Protocol address of the instance in the database to the metadata of the instance in the service discovery center.
[0090] Specifically, the service management center stores the Internet Protocol address of the instance and the interface information of the instance in a one-to-one correspondence in the database used by the service management center. When the instance is lost and then comes back online, the service discovery center monitors that the instance is back online. Based on the subscribed online monitoring event, the service discovery center sends an online notification to the service management center. Based on the online notification, the service management center confirms that the instance is lost and then comes back online, and confirms the Internet Protocol address of the instance. The service management center obtains the interface information of the instance from the database based on the Internet Protocol address of the instance. The service management center restores the interface information of the instance to the metadata of the instance in the service discovery center.
[0091] In this embodiment, the service management center can restore the interface information of the instance stored in the database to the metadata of the instance in the service discovery center when the instance is disconnected and then online. In this way, after the device where the instance is located is disconnected and restarted, the instance metadata can be automatically restored, thereby avoiding the loss of interface information and ensuring that the gateway can obtain the interface information of the instance, thereby ensuring the reliability of access to the service.
[0092] In one embodiment, Figure 3 As shown, part of the process of the service management center managing the database is shown. Specifically, the service management center obtains the interface registration request of the service instance. The service management center determines whether the instance has subscribed to the online listening event. If the online listening event is not subscribed, the online listening event is subscribed for the instance. The service management center obtains the access path from the interface registration request and stores it as interface information in the metadata of the instance of the service discovery center. Among them, the access port can also be obtained from the interface registration request and stored together with the access path as interface information. The service management center determines whether the database has already stored the interface information ( Figure 3 Taking the access path as an example), if it is not stored, a new database record is added to record the new interface information; if the interface information has been stored, the database record is updated to update the storage time of the interface information.
[0093] In one embodiment, Figure 4As shown, the process of restoring instance metadata by the service management center is shown. Specifically, after the service management center confirms that the instance is online, it queries the database based on the Internet Protocol address corresponding to the instance to see whether the instance interface information is stored. If the instance interface information is stored, it further determines whether the instance is disconnected. If the instance is disconnected, the instance interface information is restored to the instance metadata.
[0094] In one embodiment, matching the target access path with the access path in the target metadata includes: the gateway obtains metadata of multiple instances of the service from the service discovery center; traverses the metadata of the multiple instances, and matches the target access path with the access path in the traversed metadata; determines the instance to which the access path that meets the matching requirements belongs, and obtains an instance set; the gateway selects the target instance from the instance set according to the routing policy.
[0095] Specifically, after the gateway obtains metadata of multiple instances of the service from the service discovery center, it traverses the metadata of the multiple instances and matches the target access path with the short path in the traversed metadata. If the match is successful, the instance to which the matched access path belongs is determined, and the instance is put into the set, thereby obtaining the final instance set. The gateway selects an instance from the instance set according to the routing policy as the target instance.
[0096] In one embodiment, the routing strategy is implemented by a client load balancing component, and the gateway uses the routing strategy implemented by the client load balancing component to select a target instance for routing, thereby achieving load balancing. Among them, the client load balancing component is a component used to implement client load balancing in the microservice framework. The microservice framework can provide a custom management object to use the custom management object to perform path matching to obtain an instance set. It can be understood that after the custom management object obtains the instance set, the client load balancing component can select the target instance from the instance set based on the routing strategy, thereby achieving load balancing processing.
[0097] Specifically, the custom management object can obtain the target access path specified by the access request based on the access request. The custom management object obtains all instances of the service and traverses all instances. The custom management object obtains the metadata of the instance, matches the access path in the metadata with the target access path, and if the match is successful, puts the instance into the optional list. After the traversal is completed, the custom management object can obtain the final optional list, that is, the instance set. The client load balancing component can select an instance from the instance set as the target instance for routing according to the routing policy, thereby achieving access to the service.
[0098] In one embodiment, the microservice framework may be Spring Cloud. Spring Cloud is a framework dedicated to distributed systems and cloud services. The load balancing component is a Ribbon component used to implement client load balancing in the microservice framework Spring Cloud. The custom management object may be a bean. It can be understood that all objects that need to be managed in the container are defined as a bean in XML.
[0099] In this embodiment, after the gateway obtains the instance set, it identifies the target instance from the instance set according to the routing policy, and utilizes the existing functions of the gateway such as authentication, flow control, load balancing, etc. to improve the availability and security of service access.
[0100] In one embodiment, the interface information of the target instance includes the access port and access path corresponding to the target instance; the gateway routes the access request to the target instance in the service based on the interface information of the target instance to access the service, including: the gateway routes the access request to the target instance according to the Internet Protocol address, access port and access path corresponding to the target instance to access the service.
[0101] In one embodiment, an instance corresponds to at least one port and at least one access path.
[0102] Specifically, the interface of the target instance includes the access port and access path corresponding to the target instance. The gateway routes the access request to the target instance according to the Internet Protocol address, access port and access path corresponding to the target instance to access the target instance, that is, to access the service to which the target instance belongs.
[0103] In this embodiment, after the gateway obtains the access port and the access path, it accesses the target instance based on the Internet Protocol address, access port and access path corresponding to the instance. In this way, the device accessing the service does not need to pay attention to the access port and the Internet Protocol address of the instance, but the gateway obtains the access port and performs routing. In the case where the port of the instance changes or there are multiple ports of the instance, the device accessing the service can access the instance of the service without any processing, so that the access to the service is flexible and the service is accessed in a dynamic routing manner. In addition, for services running in a container environment, the problem that services in the container environment are difficult to access externally is solved, and no other port mapping is required, which solves the problem of opening ports of the container environment to the external network.
[0104] In one embodiment, after the gateway receives an access request for a service, confirming the target access path specified by the access request through the gateway includes: after the gateway receives the access request for the service, obtaining the request address used to send the access request; extracting the target access path from the request address.
[0105] In one embodiment, the device accessing the service sends an access request to the gateway via the http (Hypertext Transfer Protocol) communication protocol.
[0106] In one embodiment, the request address may be generated by a Uniform Resource Locator (URL).
[0107] Specifically, the access end for accessing the service sends an access request to the gateway. After the gateway receives the access request for the service, the gateway obtains the request address used to send the access request and extracts the target access path from the request address.
[0108] In this embodiment, the request address used by the access request sent by the access terminal is obtained; the target access path is extracted from the request address, so that when the target access path changes, the access terminal only needs to modify the request address. The gateway extracts the target access path from the request address, so that the gateway can easily obtain the target access path, thereby further improving the flexibility of service access.
[0109] In one embodiment, the target metadata is metadata of an online instance of a service in the service discovery center.
[0110] Specifically, when an instance of a service goes online, the service discovery center will be notified, so the service discovery center can confirm the online instance. The target metadata obtained by the gateway from the service discovery center is the metadata of the instance of the service that the service discovery center confirms to be online. It can be understood that the service discovery center further determines whether the instance is online, so that the instance corresponding to the target metadata obtained by the gateway is the online instance, and the metadata of the offline or disconnected instance will not be obtained by the gateway, thereby ensuring that the target instance obtained by the gateway based on the target metadata is online. Therefore, the accuracy of the routing is guaranteed.
[0111] In one embodiment, multiple instances of a service send interface registration requests to a service management center, and the service management center obtains the interface registration requests sent by the multiple instances of the service, and obtains the corresponding interface information of the multiple instances based on the interface registration requests; the interface information includes the corresponding access path of the instance. For multiple instances, the service management center stores the corresponding interface information of the instance in the metadata of the instance in the service discovery center, and subscribes to the online listening event to receive the instance online notification. In the case where the instance is disconnected and restarted online, the service management center can restore the interface information stored in the database to the metadata of the instance in the service discovery center. After the gateway receives the access request for the service, the gateway confirms the target access path specified by the access request. Among them, the gateway can extract the target access path from the request address used to send the access request. The gateway matches the target access path with the access path in the target metadata; wherein the target metadata is the metadata of multiple instances of the service in the service discovery center. The gateway obtains a set of matching instances according to the matched access path, and confirms a target instance from the integration according to the routing policy. The gateway determines the interface information of the target instance corresponding to the matched access path. The gateway routes the access request to the target instance of the service based on the port, access path, and Internet Protocol address corresponding to the target instance to access the service to which the target instance belongs.
[0112] It should be understood that, although each step in the flow chart in the embodiment of the present application is shown in sequence according to the indication of the arrow, these steps are not necessarily performed in sequence according to the order indicated by the arrow. Unless there is clear explanation in this article, the execution of these steps does not have strict order restriction, and these steps can be performed in other order. Moreover, at least a portion of the steps in the flow chart may include a plurality of steps or a plurality of stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with at least a portion of the steps or stages in other steps or other steps.
[0113] Based on the same inventive concept, the embodiment of the present application also provides a service access system for implementing the service access method involved above. The implementation scheme for solving the problem provided by the system is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more system embodiments provided below can refer to the limitations on the service access method above, and will not be repeated here.
[0114] In one embodiment, Figure 6 As shown, a service access system 600 is provided, including: a service management center 602 and a gateway 604, wherein:
[0115] The service management center 602 is used to obtain interface registration requests sent by multiple instances of the service, and obtain corresponding interface information of the multiple instances based on the interface registration requests; the interface information includes the corresponding access path of the instance, and the multiple instances are deployed in the container; for each of the multiple instances, the service management center 602 stores the corresponding interface information of the instance in the metadata of the instance in the service discovery center to complete the interface registration.
[0116] Gateway 604 is used to confirm the target access path specified in the access request through the gateway after the gateway 604 receives the access request for the service; match the target access path with the access path in the target metadata; the target metadata is the metadata of the instance in the service discovery center; determine the interface information of the target instance corresponding to the matched access path; the gateway 604 routes the access request to the target instance of the service based on the interface information of the target instance to access the service.
[0117] In one embodiment, the service management center 602 is also used to determine whether the instance has subscribed to the online monitoring event; if the instance has not subscribed to the online monitoring event, the service management center 602 subscribes to the online monitoring event for the instance from the service discovery center; the service discovery center monitors the online status of the instance based on the subscribed online monitoring event; after monitoring that the instance is in the online state, the service discovery center sends an online notification to the service management center 602.
[0118] In one embodiment, the online notification is sent to the service management center by the service discovery center when it detects that the instance is back online after being disconnected. The service management center 602 is also used to store the Internet Protocol address of the instance and the interface information of the instance in a one-to-one correspondence in the database of the service management center 602; the service discovery center is also used to send the online notification to the service management center 602 when it detects that the instance is back online after being disconnected; after receiving the online notification, the service management center 602 restores the interface information corresponding to the Internet Protocol address in the database to the metadata of the instance in the service discovery center.
[0119] In one embodiment, gateway 604 is also used to traverse the target metadata, match the target access path with the access paths in the metadata of multiple instances; determine the instance to which the access path that meets the matching requirements belongs to obtain an instance set; and select the target instance from the instance set according to the routing policy.
[0120] In one embodiment, the interface information of the target instance includes the access port and access path corresponding to the target instance; the gateway 604 is also used to route the access request to the target instance according to the Internet Protocol address, access port and access path corresponding to the target instance to access the service.
[0121] In one embodiment, the gateway 604 is further configured to obtain a request address used to send the access request after the gateway 604 receives the access request for the service; and extract a target access path from the request address.
[0122] The above service access system obtains interface registration requests sent by multiple instances of the service through the service management center, and obtains interface information corresponding to the multiple instances based on the interface registration requests; the interface information includes the corresponding access path of the instance. The multiple instances are deployed in a container. For each of the multiple instances, the service management center stores the corresponding interface information of the instance in the metadata of the instance in the service discovery center to complete the interface registration. In this way, the instance can actively publish and store the interface information through the interface registration request. After the gateway receives the access request for the service, the gateway confirms the target access path specified by the access request; matches the target access path with the access path in the target metadata; the target metadata is the metadata of the instance of the service in the service discovery center. Determine the interface information of the target instance corresponding to the matched access path; so that the gateway obtains the required interface information. The gateway routes the access request to the target instance of the service based on the interface information of the target instance to access the service. Therefore, an interface registration request is actively initiated through the service instance, and the service discovery center is enabled to store and manage the interface information through the service management center, so that the gateway can obtain the interface information of each instance, and then access the service instance based on the instance interface information, thereby solving the problem of the service being difficult to access externally and improving the flexibility of service access.
[0123] For the specific limitations of the above-mentioned service access system, please refer to the limitations of the above-mentioned service access, which will not be repeated here. Each device in the above-mentioned service access system can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned devices can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above devices.
[0124] In one embodiment, a service access device is provided, comprising:
[0125] An acquisition module, used to acquire interface registration requests sent by multiple instances of a service, and acquire corresponding interface information of the multiple instances based on the interface registration requests; the interface information includes an access path corresponding to the instance; the multiple instances are deployed in a container;
[0126] A storage module, used for storing the interface information corresponding to each instance in the multiple instances into the metadata of the instance to complete the interface registration;
[0127] A confirmation module, configured to confirm a target access path specified in the access request after receiving the access request for the service;
[0128] A matching module is used to match a target access path with an access path in target metadata; the target metadata is metadata of an instance of a service;
[0129] The matching module is also used to determine the interface information of the target instance corresponding to the matched access path;
[0130] The routing module is used to route the access request to the target instance of the service based on the interface information of the target instance so as to access the service.
[0131] In one embodiment, the acquisition module is also used to perform the following processing for any one of the multiple instances: determine whether any one of the instances is subscribed to the online listening event; if any one of the instances is not subscribed to the online listening event, subscribe to the online listening event for any one of the instances; monitor the online status of any one of the instances based on the subscribed online listening event; after the service discovery center monitors that the instance is in the online state, the service management center sends an online notification to the service management center.
[0132] In one embodiment, the online notification is sent by the service discovery center to the service management center when it detects that the instance has lost connection and is back online; the service access device also includes a recovery module, which is used to perform the following processing for any one of the multiple instances: storing the Internet Protocol address of any instance and the interface information of any instance in a database in a one-to-one correspondence; after any one of the instances is back online, restoring the interface information corresponding to the Internet Protocol address in the database to the metadata of any one of the instances.
[0133] In one embodiment, the matching module is further used to: traverse the target metadata, match the target access path with the access path in the traversed metadata; determine the instance to which the access path that meets the matching requirements belongs, and obtain an instance set; and select the target instance from the instance set according to the routing policy.
[0134] In one embodiment, the interface information of the target instance includes the access port and access path corresponding to the target instance; the routing module is also used to: route the access request to the target instance according to the Internet Protocol address, access port and access path corresponding to the target instance to access the service.
[0135] In one embodiment, the confirmation module is further used to: after receiving an access request for a service, obtain a request address used to send the access request; and extract a target access path from the request address.
[0136] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store interface information data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a service access method is implemented.
[0137] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0138] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0139] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0140] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0141] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0142] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0143] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A service access method, characterized in that: The method comprises: The service management center obtains interface registration requests sent by multiple instances of the service, and obtains corresponding interface information of the multiple instances based on the interface registration requests; the interface information includes the corresponding access path of the instance; the multiple instances are deployed in containers; For each instance of the multiple instances, the service management center stores the interface information corresponding to the instance in the metadata of the instance in the service discovery center to complete the interface registration; After the gateway receives the access request for the service, confirming, through the gateway, the target access path specified by the access request; The gateway matches the target access path with the access path in the target metadata, determines the instance to which the access path that meets the matching requirements belongs, and obtains an instance set; the target metadata is the metadata of the instance of the service in the service discovery center; The gateway selects a target instance from the instance set according to a routing policy, and obtains interface information of the target instance from the target metadata; the routing policy is implemented by a client load balancing component; The gateway routes the access request to the target instance of the service based on the interface information of the target instance to access the service.
2. The method according to claim 1, characterized in that The method further comprises: For any one of the multiple instances, perform the following processing: The service management center determines whether any one of the instances subscribes to the online monitoring event; If any one of the instances has not subscribed to the online monitoring event, the service management center subscribes the online monitoring event to the service discovery center for the any one of the instances; The service discovery center monitors the online status of any one of the instances based on the subscribed online monitoring event; After monitoring that the instance is in an online state, the service discovery center sends an online notification to the service management center.
3. The method according to claim 2, characterized in that The online notification is sent by the service discovery center to the service management center when the service discovery center monitors that the instance is back online after being disconnected; the method also includes: The service management center performs the following processing for any one of the multiple instances: The Internet Protocol address of any one of the instances and the interface information of any one of the instances are stored in a database of the service management center in a one-to-one correspondence; After any one of the instances comes back online, the interface information corresponding to the Internet Protocol address in the database is restored to the metadata of the any one of the instances.
4. The method according to claim 1, characterized in that: The gateway matching the target access path with the access path in the target metadata includes: The gateway traverses the target metadata and matches the target access path with the access path in the traversed metadata.
5. The method according to any one of claims 1 to 4, characterized in that: The interface information of the target instance includes the access port and access path corresponding to the target instance; The gateway routing the access request to the target instance of the service based on the interface information of the target instance to access the service includes: The gateway routes the access request to the target instance according to the corresponding Internet Protocol address, access port and access path of the target instance to access the service.
6. The method according to any one of claims 1 to 4, characterized in that: After the gateway receives the access request for the service, confirming, by the gateway, the target access path specified by the access request includes: After the gateway receives the access request for the service, the gateway obtains the request address used to send the access request; The gateway extracts a target access path from the request address.
7. The method according to any one of claims 1 to 4, characterized in that: The target metadata is metadata of an online instance of the service in the service discovery center.
8. A service access system, characterized in that: The system comprises: a service management center and a gateway; The service management center is used to obtain interface registration requests sent by multiple instances of a service, and obtain interface information corresponding to the multiple instances based on the interface registration requests; the interface information includes access paths corresponding to the instances; the multiple instances are deployed in containers; for each of the multiple instances, the interface information corresponding to the instance is stored in the metadata of the instance in the service discovery center to complete the interface registration; The gateway is used to confirm the target access path specified in the access request for the service after receiving the access request; match the target access path with the access path in the target metadata, determine the instance to which the access path that meets the matching requirements belongs, and obtain an instance set; the target metadata is the metadata of the instance of the service in the service discovery center; select the target instance from the instance set according to the routing policy, and obtain the interface information of the target instance from the target metadata; the routing policy is implemented by the client load balancing component; and route the access request to the target instance of the service based on the interface information of the target instance to access the service.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
