A service switching method and device
By obtaining the master-slave instance based on the computer room identification of the provider service and performing cross-client retry, the problem of randomness of service abnormal retry and low switching timeliness is solved, and efficient service retry and switching is achieved.
Patent Information
- Application Number
- CN202011331403.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-24
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2040-11-24
AI Technical Summary
In the prior art, service exception retry is random, and it is impossible to guarantee cross-campus room resumption. RPC service switching depends on the switching of service alias, resulting in low switching timeliness and affecting the availability of other services.
By obtaining the master or slave instance from the instance container based on the computer room identification where the provider service is located, if an exception is called, cross-computer room retry is performed to achieve targeted and controllable abnormal retry, and to realize service switching through dynamic configuration , avoid restarting the container.
It solves the problem of random service switching and unguaranteeing cross-computer room retry, improves the pertinence and timeliness of service retry, and ensures the reliability of cross-computer room requests and the efficiency of service switching.
Smart Images

Figure CN113760445B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a service switching method and device. Background Art
[0002] To ensure high availability of RPC services, when an RPC service exception occurs (such as no service provider exception, timeout exception), it is necessary to have cross-data center disaster recovery and retry capabilities. When the RPC service provider alias is switched, the RPC service consumer must also switch in time to cope with the disaster recovery capabilities of the dependent service.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] Service exception retries are random and cannot guarantee cross-data center retries. For example, when all services in Data Center A are abnormal, the ideal scenario is that requests to Data Center A will automatically retry to Data Center B after discovering the abnormality. However, in actual scenarios, due to the randomness of the retry request, the request will be sent to Data Center A again, causing the request to fail.
[0005] RPC service switching mainly depends on the switching of service aliases, but service aliases are mostly configured in resource files. Resource files are only reloaded when the service container is started. Once service switching is involved, the container needs to be restarted. Therefore, restarting the container to switch the service alias is less effective and will make other services in the container unavailable. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides a service switching method and device to solve the technical problem that service switching is random and cannot guarantee cross-machine room retry.
[0007] To achieve the above object, according to one aspect of an embodiment of the present invention, a service switching method is provided, comprising:
[0008] According to the identifier of the computer room where the consumer service is located, the identifier of the first computer room where the provider service is located is obtained from the service call strategy;
[0009] According to the first computer room identifier of the provider service, obtaining the first main instance of the provider service from the instance container; wherein the first main instance identifier of the provider service is the same as the first computer room identifier;
[0010] Calling a first master instance of the provider service to initiate a request to call the provider service deployed in the first computer room;
[0011] If the calling result of the first main instance of the provider service is a calling exception, a cross-computer room retry is performed.
[0012] Optionally, if the calling result of the first primary instance of the provider service is a calling exception, a cross-computer room retry is performed, including:
[0013] Determine whether the calling result of the first primary instance of the provider service is a calling exception;
[0014] If yes, obtaining the first slave instance of the provider service from the instance container; wherein the first slave instance identifier of the provider service is different from the first computer room identifier, and the first slave instance identifier of the provider service is the same as the second computer room identifier;
[0015] The first slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
[0016] Optionally, determining whether the call result of the first primary instance of the provider service is a call exception includes:
[0017] Determining whether a first primary instance of the provider service throws an exception;
[0018] If so, continue to determine whether the exception is a remote procedure call exception.
[0019] Optionally, it also includes:
[0020] If the first computer room fails, obtaining the second primary instance of the provider service from the instance container; wherein the second primary instance identifier of the provider service is different from the first computer room identifier, and the second primary instance identifier of the provider service is the same as the second computer room identifier;
[0021] The second main instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
[0022] Optionally, after calling the second primary instance of the provider service, the method further includes:
[0023] Determine whether the calling result of the second primary instance of the provider service is a calling exception;
[0024] If yes, obtaining a second slave instance of the provider service from the instance container; wherein the second slave instance identifier of the provider service is different from the first computer room identifier, and the second slave instance identifier of the provider service is the same as the second computer room identifier;
[0025] The second slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
[0026] Optionally, the identifier of the computer room where the consumer service is located is the same as the identifier of the first computer room where the provider service is located.
[0027] Optionally, calling the first main instance of the provider service to initiate a request to call the provider service deployed in the first computer room includes:
[0028] Tracking a first primary instance of the provider service;
[0029] Print the request input parameters of the provider service;
[0030] Calling a first master instance of the provider service to initiate a request to call the provider service deployed in the first computer room;
[0031] Prints the request output parameters of the provider service.
[0032] In addition, according to another aspect of an embodiment of the present invention, a service switching device is provided, including:
[0033] An acquisition module, used to acquire the first computer room identifier where the provider service is located from the service call strategy according to the computer room identifier where the consumer service is located;
[0034] A switching module is used to obtain the first main instance of the provider service from the instance container according to the identifier of the first computer room where the provider service is located; call the first main instance of the provider service to initiate a request to call the provider service deployed in the first computer room; if the call result of the first main instance of the provider service is a call exception, retry across computer rooms; wherein the identifier of the first main instance of the provider service is the same as the identifier of the first computer room.
[0035] Optionally, the switching module is further used for:
[0036] Determine whether the calling result of the first primary instance of the provider service is a calling exception;
[0037] If yes, obtaining the first slave instance of the provider service from the instance container; wherein the first slave instance identifier of the provider service is different from the first computer room identifier, and the first slave instance identifier of the provider service is the same as the second computer room identifier;
[0038] The first slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
[0039] Optionally, the switching module is further used for:
[0040] Determining whether a first primary instance of the provider service throws an exception;
[0041] If so, continue to determine whether the exception is a remote procedure call exception.
[0042] Optionally, the switching module is further used for:
[0043] If the first computer room fails, obtaining the second primary instance of the provider service from the instance container; wherein the second primary instance identifier of the provider service is different from the first computer room identifier, and the second primary instance identifier of the provider service is the same as the second computer room identifier;
[0044] The second main instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
[0045] Optionally, the switching module is further used for:
[0046] After calling the second main instance of the provider service, determining whether the calling result of the second main instance of the provider service is a calling exception;
[0047] If yes, obtaining a second slave instance of the provider service from the instance container; wherein the second slave instance identifier of the provider service is different from the first computer room identifier, and the second slave instance identifier of the provider service is the same as the second computer room identifier;
[0048] The second slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
[0049] Optionally, the identifier of the computer room where the consumer service is located is the same as the identifier of the first computer room where the provider service is located.
[0050] Optionally, the switching module is further used for:
[0051] Tracking a first primary instance of the provider service;
[0052] Print the request input parameters of the provider service;
[0053] Calling a first master instance of the provider service to initiate a request to call the provider service deployed in the first computer room;
[0054] Prints the request output parameters of the provider service.
[0055] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, including:
[0056] one or more processors;
[0057] a storage device for storing one or more programs,
[0058] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any one of the above embodiments.
[0059] According to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described in any one of the above embodiments is implemented.
[0060] An embodiment of the above invention has the following advantages or beneficial effects: because the first main instance of the provider service is obtained from the instance container according to the first computer room identifier where the provider service is located, the first main instance is called, and if the call is abnormal, a cross-computer room retry is performed, so the technical problem of random service switching and inability to guarantee cross-computer room retry in the prior art is overcome. The embodiment of the present invention is based on the configuration method, and the abnormal retry strategy is determined by the service consumer, so that the service retry is targeted and controllable, and the problem of random service retry is solved; if the provider service is switched, the consumer service only needs to modify the dynamic configuration, and there is no need to republish the service, which is more timely.
[0061] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0063] Figure 1 is a schematic diagram of the main process of the service switching method according to an embodiment of the present invention;
[0064] Figure 2 is a schematic diagram of the main process of a service switching method according to a reference embodiment of the present invention;
[0065] Figure 3 is a schematic diagram of the configuration relationship between an RPC proxy object and an RPC instance object according to an embodiment of the present invention;
[0066] Figures 4a-4d A schematic diagram of configuration information according to an embodiment of the present invention;
[0067] Figure 5 is a schematic diagram of the main process of a service switching method according to a reference embodiment of the present invention;
[0068] Figure 6 is a schematic diagram of main modules of a service switching device according to an embodiment of the present invention;
[0069] Figure 7 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0070] Figure 8 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0071] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0072] Figure 1 FIG. 1 is a schematic diagram of the main process of the service switching method according to an embodiment of the present invention. As an embodiment of the present invention, Figure 1 As shown, the service switching method may include:
[0073] Step 101, according to the identifier of the computer room where the consumer service is located, obtain the first computer room identifier where the provider service is located from the service call strategy.
[0074] In an embodiment of the present invention, the consumer service calls the provider service, and determines the first computer room identifier where the provider service is located according to the service call strategy. Optionally, the computer room identifier where the consumer service is located is the same as the first computer room identifier where the provider service is located. For example, if the computer room identifier where the consumer service is located is LF, then the first computer room identifier where the provider service is located is also LF; if the computer room identifier where the consumer service is located is HT, then the first computer room identifier where the provider service is located is also HT. The same computer room call principle is met to improve service performance.
[0075] Step 102: acquiring a first primary instance of the provider service from an instance container according to the first computer room identifier where the provider service is located; wherein the first primary instance identifier of the provider service is the same as the first computer room identifier.
[0076] In the embodiment of the present invention, instances (Beans) with different service identifiers need to be pre-registered in the Spring container, and the identifiers of these instances are the same as the computer room identifier. For example, there are computer room LF and computer room HT, then instance LF and instance HT are registered in the Spring container, for computer room LF, instance LF is the master instance, and instance HT is the slave instance, for computer room HT, instance HT is the master instance, and instance LF is the slave instance.
[0077] If the computer room where the provider service is located is identified as the first computer room identification, the first primary instance of the provider service is obtained from the Spring container, and the first primary instance identification of the provider service is the same as the first computer room identification. For example, if the computer room where the provider service is located is identified as LF, the instance LF is obtained from the Spring container.
[0078] Step 103: Call the first main instance of the provider service to initiate a request to call the provider service deployed in the first computer room.
[0079] After obtaining the first main instance of the provider service from the instance container, the first main instance is called to initiate a request to call the provider service deployed in the first computer room, that is, the request is sent to the provider service deployed in the first computer room.
[0080] Optionally, step 103 may include: tracking the first main instance of the provider service; printing the request input parameters of the provider service; calling the first main instance of the provider service to initiate a request to call the provider service deployed in the first computer room; printing the request output parameters of the provider service. The embodiment of the present invention can also collect logs in a unified manner, intercept them in the service dimension, and centrally solve the monitoring tracking and log printing problems, so as to reduce the R&D burden and improve the R&D efficiency.
[0081] Step 104: If the calling result of the first main instance of the provider service is a calling exception, a cross-computer room retry is performed.
[0082] Optionally, after step 103, determine whether the call result of the first main instance of the provider service is a call exception; if so, obtain the first slave instance of the provider service from the instance container; wherein the first slave instance identifier of the provider service is different from the first computer room identifier, and the first slave instance identifier of the provider service is the same as the second computer room identifier; call the first slave instance of the provider service to initiate a request to call the provider service deployed in the second computer room. When an exception occurs in the call of the first main instance of the provider service, the first slave instance of the provider service can be obtained from the Spring container based on a pre-configured exception retry strategy, wherein the first slave instance identifier is different from the first computer room identifier, and the first slave instance identifier is the same as the second computer room identifier, and then the first slave instance is called. Therefore, when a service is abnormal, an embodiment of the present invention can ensure retry across computer rooms and solve the problem of randomness in service switching.
[0083] For example: pre-register the RPC instances with two identifiers, HT and LF, of the querySku interface to the Spring container. If the first computer room where the provider service is located is identified as LF, the first master instance LF will be called first. When the first master instance LF has a call exception, the first slave instance HT will be called for an exception retry, that is, the service deployed in the second computer room HT will be called, thereby achieving the purpose of cross-computer room retry. If the first slave instance HT also has a call exception, this request fails.
[0084] It should be pointed out that the first slave instance is not limited to one, there can be multiple. If there are multiple first slave instances, the exception retry order of these first slave instances can be specified through the exception retry strategy. For example, if there are computer room LF, computer room HT and computer room LL, then the instance LF, instance HT and instance LL are registered in the Spring container. For the computer room LF, the instance LF is the master instance and the instance HT is the slave instance. For the computer room HT, the instance HT is the master instance and the instance LF and computer room LL are slave instances. If the first computer room where the provider service is located is identified as LF, the first master instance LF will be called first. When the first master instance LF has a call exception, the first slave instance HT or LL will be called for exception retry. The calling order of the first slave instances HT and LL can be specified through the exception retry strategy. For example, the first slave instance HT is called first for exception retry. When the call fails, the first slave instance LL is called for exception retry.
[0085] Optionally, determining whether the call result of the first main instance of the provider service is a call exception includes: determining whether the first main instance of the provider service throws an exception; if so, continuing to determine whether the exception is a remote procedure call exception. When determining whether the call result of the instance is a call exception, first determine whether the instance throws an exception, and if so, continue to determine whether the exception is an RPC exception, thereby accurately determining whether it is an RPC service call exception of the instance.
[0086] When calling the first slave instance, logs can also be collected uniformly, intercepted in the service dimension, and the monitoring tracking and log printing problems can be solved centrally, so as to reduce the R&D burden and improve R&D efficiency. Specifically, the first slave instance of the provider service is tracked; the request input parameters of the provider service are printed; the first slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room; and the request output parameters of the provider service are printed.
[0087] The embodiment of the present invention is based on the configuration mode, and the service consumer configures the abnormal retry strategy, and the configuration specifies the normal request service (master instance) and the abnormal retry service (slave instance), so that the service retry is targeted and controllable, solves the problem of random service switching, and ensures cross-machine room service retry. Moreover, the service alias can be dynamically switched based on the configuration to improve the timeliness of service switching.
[0088] According to the various embodiments described above, it can be seen that the embodiment of the present invention obtains the first main instance of the provider service from the instance container according to the first computer room identifier where the provider service is located, calls the first main instance, and performs a cross-computer room retry if the call is abnormal. This technical means solves the technical problem of random service switching and inability to guarantee cross-computer room retry in the prior art. The embodiment of the present invention is based on the configuration method, and the service consumer determines the abnormal retry strategy, so that the service retry is targeted and controllable, solving the problem of random service retry; if the provider service switches, the consumer service only needs to modify the dynamic configuration, without re-publishing the service, which is more timely.
[0089] Figure 2 FIG. 1 is a schematic diagram of the main process of a service switching method according to a reference embodiment of the present invention. As another embodiment of the present invention, Figure 2 As shown, the service switching method may include:
[0090] Step 201, according to the identifier of the computer room where the consumer service is located, obtain the first computer room identifier where the provider service is located from the service call strategy.
[0091] Step 202: Acquire a first primary instance of the provider service from an instance container according to the first computer room identifier where the provider service is located, wherein the first primary instance identifier of the provider service is the same as the first computer room identifier.
[0092] Step 203: Call the first main instance of the provider service to initiate a request to call the provider service deployed in the first computer room.
[0093] Step 204: If the first computer room fails, obtain the second primary instance of the provider service from the instance container.
[0094] For example, there are computer room LF and computer room HT. If the computer room LF fails, the second main instance of the provider service is obtained from the instance container. The second main instance identifier of the provider service is different from the first computer room identifier, and the second main instance identifier of the provider service is the same as the second computer room identifier, that is, the second main instance of the provider service is HT, thereby realizing service hot switching.
[0095] Step 205: Call the second main instance of the provider service to initiate a request to call the provider service deployed in the second computer room.
[0096] After obtaining the second main instance of the provider service from the instance container, the second main instance is called to initiate a request to call the provider service deployed in the second computer room, that is, to send the request to the provider service deployed in the second computer room.
[0097] When calling the second main instance, logs can also be collected uniformly, intercepted in the service dimension, and the monitoring tracking and log printing problems can be solved centrally, so as to reduce the R&D burden and improve R&D efficiency. Specifically, the second main instance of the provider service is tracked; the request input parameters of the provider service are printed; the second main instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room; and the request output parameters of the provider service are printed.
[0098] Step 206, determining whether the call result of the second primary instance of the provider service is a call exception; if so, executing step 207; if not, ending.
[0099] Step 207: Acquire a second slave instance of the provider service from the instance container.
[0100] If the call result of the second master instance of the provider service is abnormal, the second slave instance of the provider service is obtained from the instance container, and the second slave instance identifier of the provider service is different from the first computer room identifier, and the second slave instance identifier of the provider service is the same as the second computer room identifier. In other words, the second master instance identifier is the same as the second slave instance identifier. Regardless of which computer room fails, the second master instance identifier and the second slave instance identifier are both identifiers of the computer room that has not failed, so as to realize service hot switching.
[0101] Step 208: Call the second slave instance of the provider service to initiate a request to call the provider service deployed in the second computer room.
[0102] For example: pre-register RPC instances with two identifiers, querySku interface HT and LF, to the Spring container. If the HT in the computer room fails, the second master instance LF will be called first. When a call exception occurs in the second master instance LF, the second slave instance LF will be called again for an exception retry to achieve the purpose of service hot switching.
[0103] It should be noted that the second slave instance is not limited to one, and there may be multiple second slave instances. If there are multiple second slave instances, the exception retry order of these second slave instances can be specified through the exception retry policy.
[0104] When calling the second slave instance, logs can also be collected uniformly, intercepted in the service dimension, and the monitoring tracking and log printing problems can be solved centrally, so as to reduce the R&D burden and improve R&D efficiency. Specifically, the second slave instance of the provider service is tracked; the request input parameter of the provider service is printed; the second slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room; and the request output parameter of the provider service is printed.
[0105] In addition, the specific implementation content of the service switching method in a reference embodiment of the present invention has been described in detail in the service switching method described above, so the repeated content will not be described here.
[0106] The embodiment of the present invention can be expanded based on the MethodInterceptor in the aopalliance extension package, so that each RPC request passes through the unified interceptor, obtains the interface configuration information from the configuration center, and then determines the instance of the provider service based on the interface configuration information, and finally calls the remote service, thereby expanding the cross-computer room retry, service hot switching, and branch computer room monitoring capabilities on the basis of the original remote service call.
[0107] Figure 3 Schematic diagram of the configuration relationship between the RPC proxy object and the RPC instance object according to an embodiment of the present invention. Figure 3 As shown, the proxy object of the RPC instance is used to call the RPC service. An RPC proxy object can contain multiple RPC instances. The RPC instance is used to initiate an RPC call and is the instantiation result of the remote service. Different RPC instances need to be configured with different RPC instance identifiers to call the same service in different computer rooms.
[0108] The proxy object of the RPC instance is based on Spring's AOP proxy implementation. An example of configuring the proxy-based AOP implementation is shown below. Figure 4a As shown in the figure, proxyInterfaces is the full path of the interface to be proxied, and interceptorNames points to the reference of the service cross-machine room retry configuration. Figure 4b As shown, only one instance is required to configure cross-data center retry service ( Figure 3 The cross-machine room retry strategy configuration bean in , where:
[0109] Services attribute, map structure, key is the full path of the interface of the proxied RPC instance, value is the call strategy configuration details of this RPC interface, data type is ServiceConfig, detailed properties are as follows Figure 4c As shown;
[0110] The appName attribute is used to register the interface method monitoring tracking point usage, which is the name of the current application;
[0111] umpKeyPrefix attribute, used for method monitoring fixed prefix, to facilitate the distinction and organization of method monitoring keys;
[0112] The group attribute is used to identify the computer room where the provider service is located, and obtain the RPC call configuration information of the specified computer room based on this identifier. It is set through the program configuration file and reloaded to take effect when the application service is released. The method's computer room monitoring is implemented based on this attribute. For example, the service located in the LF computer room can be configured as group_lf, and the container service located in the HT computer room can be configured as group_ht;
[0113] The configCenter property is used to obtain the dynamically configured configuration center instance, such as DUCC, Nacos, Apollo and other configuration center services.
[0114] The RPC interface call policy configuration specifies the retry methods supported by the interface, the consumption retry policy, and the ID associated with the configuration center information. Each RPC proxy object needs to configure the RPC interface call policy to configure the retry policy of the interface in detail. The specific configuration information is as follows: Figure 4c As shown. Among them:
[0115] The consumers attribute is a map structure. The key is the RPC instance identifier. The configuration center arranges the call order between RPC instances based on this identifier. The value is the RPC instance, and the object type is Object.
[0116] The retryMethods attribute is used to configure the method names (i.e. provider services) that support retry. If there are multiple methods, they can be separated by commas, for example: querySku, queryProduct, querySkuDetail;
[0117] The configId attribute is used to filter the configuration information of this interface from the configuration center. It is generally set to the full path of the RPC interface for easy identification.
[0118] The configuration center is mainly used to configure the cross-computer room retry strategy and computer room hot switch strategy of the RPC service. Through a certain data text format, the execution strategy and execution order arrangement of each RPC interface are configured. Configuration information data text format Figure 4c As shown, the data text is presented in JSON format, and the data consists of a 2-layer map structure:
[0119] The first layer of map structure configures the calling strategies of multiple interfaces. The key is Figure 4cThe value corresponding to the configId attribute is used to filter the configuration information of this interface from the configuration data, for example: com.xxx.ProductRpc; value is a map structure, which sets the computer room call strategy configured by the RPC interface.
[0120] The second-level map structure is the detailed calling strategy of a single interface. The key is Figure 4b The value corresponding to the group attribute in the table is used to identify the computer room where the current container service is located, and to obtain detailed calling strategies for different RPC interfaces based on the computer room dimension. The value is the calling sequence of a computer room service of the interface. "lf-ht" is two RPC instance identifiers separated by "-". "lf" and "ht" are Figure 4c The value corresponding to the key in the consumers attribute.
[0121] For example: "lf_group":"lf-ht", represents this RPC request, in the computer room LF will first call the RPC instance corresponding to the lf instance identifier (i.e. Figure 4c If an RPC exception is thrown, the ht instance object is used to identify the corresponding RPC instance (i.e. Figure 4c The productRpcHT instance pointed to by value-ref in line 5).
[0122] RPC service call orchestration supports many different forms and scenarios, as shown in the following table:
[0123]
[0124] Based on the above configuration, a complete RPC request and retry, such as Figure 5 As shown, the RPC proxy object bean receives the RPC request, and after passing through the unified interceptor, the cross-computer room retry strategy configuration bean obtains the configuration information of this interface from the configuration center according to the method path. The RPC proxy object bean implements the cross-computer room retry function and service hot switching function of the embodiment of the present invention based on the configuration information.
[0125] Cross-computer room retry function: According to the computer room identifier of the consumer service, obtain the first computer room identifier of the provider service from the service call strategy; according to the first computer room identifier of the provider service, obtain the first master instance of the provider service from the instance container; wherein the first master instance identifier of the provider service is the same as the first computer room identifier; call the first master instance of the provider service to initiate a request to call the provider service deployed in the first computer room. Determine whether the call result of the first master instance of the provider service is a call exception; if so, obtain the first slave instance of the provider service from the instance container; wherein the first slave instance identifier of the provider service is different from the first computer room identifier, and the first slave instance identifier of the provider service is the same as the second computer room identifier; call the first slave instance of the provider service to initiate a request to call the provider service deployed in the second computer room.
[0126] Service hot switching function: if the first computer room fails, obtain the second main instance of the provider service from the instance container; wherein the second main instance identifier of the provider service is different from the first computer room identifier, and the second main instance identifier of the provider service is the same as the second computer room identifier; call the second main instance of the provider service to initiate a request to call the provider service deployed in the second computer room.
[0127] The embodiment of the present invention is implemented based on the configuration center, which can support configuration changes and service hot switching at any time, further improving the timeliness, thereby improving the system's ability to handle and recover from exceptions. In addition, the embodiment of the present invention can be based on the proxy AOP implementation method, relying on XML configuration, and can be implemented using the @AspectJ annotation-driven aspect method to reduce XML configuration.
[0128] Since the embodiment of the present invention does not rely on any external resources, it can perfectly match the Spring framework. RPC service cross-machine room retry, service hot switching, monitoring tracking, and logging can all be packaged as jar packages to enable external capabilities. When using it, you only need to import the jar package and add Figures 4a-4d The configuration shown is sufficient to use this function. It does not intrude into the business code, greatly improves the function reuse, and achieves the effect of out-of-the-box use.
[0129] Figure 6 is a schematic diagram of main modules of a service switching device according to an embodiment of the present invention. Figure 6As shown, the service switching device 600 includes an acquisition module 601 and a switching module 602; the acquisition module 601 is used to obtain the first computer room identifier where the provider service is located from the service call strategy according to the computer room identifier where the consumer service is located; the switching module 602 is used to obtain the first main instance of the provider service from the instance container according to the first computer room identifier where the provider service is located; call the first main instance of the provider service to initiate a request to call the provider service deployed in the first computer room; if the call result of the first main instance of the provider service is a call exception, a cross-computer room retry is performed; wherein, the first main instance identifier of the provider service is the same as the first computer room identifier.
[0130] Optionally, the switching module 602 is further configured to:
[0131] Determine whether the calling result of the first primary instance of the provider service is a calling exception;
[0132] If yes, obtaining the first slave instance of the provider service from the instance container; wherein the first slave instance identifier of the provider service is different from the first computer room identifier, and the first slave instance identifier of the provider service is the same as the second computer room identifier;
[0133] The first slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
[0134] Optionally, the switching module 602 is further configured to:
[0135] Determining whether a first primary instance of the provider service throws an exception;
[0136] If so, continue to determine whether the exception is a remote procedure call exception.
[0137] Optionally, the switching module 602 is further configured to:
[0138] If the first computer room fails, obtaining the second primary instance of the provider service from the instance container; wherein the second primary instance identifier of the provider service is different from the first computer room identifier, and the second primary instance identifier of the provider service is the same as the second computer room identifier;
[0139] The second main instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
[0140] Optionally, the switching module 602 is further configured to:
[0141] After calling the second main instance of the provider service, determining whether the calling result of the second main instance of the provider service is a calling exception;
[0142] If yes, obtaining a second slave instance of the provider service from the instance container; wherein the second slave instance identifier of the provider service is different from the first computer room identifier, and the second slave instance identifier of the provider service is the same as the second computer room identifier;
[0143] The second slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
[0144] Optionally, the identifier of the computer room where the consumer service is located is the same as the identifier of the first computer room where the provider service is located.
[0145] Optionally, the switching module 602 is further configured to:
[0146] Tracking a first primary instance of the provider service;
[0147] Print the request input parameters of the provider service;
[0148] Calling a first master instance of the provider service to initiate a request to call the provider service deployed in the first computer room;
[0149] Prints the request output parameters of the provider service.
[0150] According to the various embodiments described above, it can be seen that the embodiment of the present invention obtains the first main instance of the provider service from the instance container according to the first computer room identifier where the provider service is located, calls the first main instance, and performs a cross-computer room retry if the call is abnormal. This technical means solves the technical problem of random service switching and inability to guarantee cross-computer room retry in the prior art. The embodiment of the present invention is based on the configuration method, and the service consumer determines the abnormal retry strategy, so that the service retry is targeted and controllable, solving the problem of random service retry; if the provider service switches, the consumer service only needs to modify the dynamic configuration, without re-publishing the service, which is more timely.
[0151] It should be noted that the specific implementation content of the service switching device of the present invention has been described in detail in the service switching method described above, so the repeated content will not be described again here.
[0152] Figure 7 An exemplary system architecture 700 to which the service switching method or service switching apparatus according to the embodiment of the present invention can be applied is shown.
[0153] like Figure 7As shown, system architecture 700 may include terminal devices 701, 702, 703, network 704 and server 705. Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0154] Users can use terminal devices 701, 702, and 703 to interact with server 705 through network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0155] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0156] Server 705 may be a server that provides various services, such as a backend management server (for example only) that provides support for shopping websites browsed by users using terminal devices 701, 702, and 703. The backend management server may analyze and process the received data such as item information query requests, and feed back the processing results to the terminal device.
[0157] It should be noted that the service switching method provided in the embodiment of the present invention is generally executed by the server 705 , and accordingly, the service switching device is generally arranged in the server 705 .
[0158] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0159] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device suitable for implementing an embodiment of the present invention. Figure 8 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0160] like Figure 8As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0161] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.
[0162] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.
[0163] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0164] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0165] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as follows: a processor includes an acquisition module, a switching module, and a calling module, wherein the names of these modules do not constitute a limitation on the modules themselves in some cases.
[0166] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by a device, the device implements the following method: according to the identifier of the computer room where the consumer service is located, obtain the identifier of the first computer room where the provider service is located from the service call strategy; according to the identifier of the first computer room where the provider service is located, obtain the first main instance of the provider service from the instance container; wherein the identifier of the first main instance of the provider service is the same as the identifier of the first computer room; call the first main instance of the provider service to initiate a request to call the provider service deployed in the first computer room; if the call result of the first main instance of the provider service is a call exception, retry across computer rooms.
[0167] According to the technical solution of the embodiment of the present invention, the first main instance of the provider service is obtained from the instance container according to the first computer room identifier where the provider service is located, and the first main instance is called. If the call is abnormal, a cross-computer room retry is performed. Therefore, the technical problem of random service switching and inability to guarantee cross-computer room retry in the prior art is overcome. The embodiment of the present invention is based on the configuration method, and the abnormal retry strategy is determined by the service consumer, so that the service retry is targeted and controllable, and the problem of random service retry is solved; if the provider service is switched, the consumer service only needs to modify the dynamic configuration, and there is no need to republish the service, which is more timely.
[0168] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A service switching method, characterized in that: include: According to the identifier of the computer room where the consumer service is located, the identifier of the first computer room where the provider service is located is obtained from the service call strategy; According to the first computer room identifier of the provider service, obtaining the first main instance of the provider service from the instance container; wherein the first main instance identifier of the provider service is the same as the first computer room identifier; Calling a first master instance of the provider service to initiate a request to call the provider service deployed in the first computer room; If the calling result of the first primary instance of the provider service is a calling exception, a cross-computer room retry is performed; If the calling result of the first primary instance of the provider service is a calling exception, a cross-computer room retry is performed, including: Determine whether the calling result of the first primary instance of the provider service is a calling exception; If yes, obtaining the first slave instance of the provider service from the instance container; wherein the first slave instance identifier of the provider service is different from the first computer room identifier, and the first slave instance identifier of the provider service is the same as the second computer room identifier; The first slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
2. The method according to claim 1, characterized in that Determining whether the call result of the first primary instance of the provider service is a call exception includes: Determining whether a first primary instance of the provider service throws an exception; If so, continue to determine whether the exception is a remote procedure call exception.
3. The method according to claim 1, characterized in that Also includes: If the first computer room fails, obtaining the second primary instance of the provider service from the instance container; wherein the second primary instance identifier of the provider service is different from the first computer room identifier, and the second primary instance identifier of the provider service is the same as the second computer room identifier; The second main instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
4. The method according to claim 3, characterized in that After calling the second main instance of the provider service, the method further includes: Determine whether the calling result of the second primary instance of the provider service is a calling exception; If yes, obtaining a second slave instance of the provider service from the instance container; wherein the second slave instance identifier of the provider service is different from the first computer room identifier, and the second slave instance identifier of the provider service is the same as the second computer room identifier; The second slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
5. The method according to claim 1, characterized in that The identifier of the computer room where the consumer service is located is the same as the identifier of the first computer room where the provider service is located.
6. The method according to claim 1, characterized in that Calling the first main instance of the provider service to initiate a request to call the provider service deployed in the first computer room, including: Tracking a first primary instance of the provider service; Print the request input parameters of the provider service; Calling a first master instance of the provider service to initiate a request to call the provider service deployed in the first computer room; Prints the request output parameters of the provider service.
7. A service switching device, characterized in that: include: An acquisition module, used to acquire the first computer room identifier where the provider service is located from the service call strategy according to the computer room identifier where the consumer service is located; A switching module, configured to obtain a first primary instance of the provider service from an instance container according to an identifier of a first computer room where the provider service is located; Calling a first master instance of the provider service to initiate a request to call the provider service deployed in the first computer room; If the call result of the first main instance of the provider service is a call exception, a cross-computer room retry is performed; wherein the first main instance identifier of the provider service is the same as the first computer room identifier; The switching module is also used for: Determine whether the calling result of the first primary instance of the provider service is a calling exception; If yes, obtaining the first slave instance of the provider service from the instance container; wherein the first slave instance identifier of the provider service is different from the first computer room identifier, and the first slave instance identifier of the provider service is the same as the second computer room identifier; The first slave instance of the provider service is called to initiate a request to call the provider service deployed in the second computer room.
8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
