Disclosure of Invention
The embodiment of the application provides a service registration method and a Apache Dubbo system, which are used for solving the problem of lower service registration and discovery efficiency caused by rapid increase of communication with a service registration center in a short time.
In a first aspect, an embodiment of the present application provides a service registration method, where the method is applied to a Apache Dubbo system, and the method includes that a service registration discovery module obtains a first URL, parses the first URL, determines that the first URL is a first type URL and an attribute value of a first attribute parameter of the first URL, when the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module caches the first URL, and when the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module generates metadata between the first URL and the first type URL cached before the first URL reaches the service registration discovery module, and sends the metadata to a service registration center.
Therefore, by adopting the method, the waiting time of the service queue can be reduced, the service registration and discovery efficiency can be improved, the network congestion condition can be relieved, and the problem that the service registration and discovery efficiency is lower due to rapid increase of communication with the service registration center in a short time can be solved by sending a plurality of URL generation metadata of the same type to the service registration center.
In one possible design, the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module caches the first URL when the first URL is not the last URL of the first type registered with the service registration center, and indicates that the service registration discovery module generates metadata with the first type of URL cached before the first URL reaches the service registration discovery module when the first URL is the last URL of the first type registered with the service registration center.
By adopting the design, by analyzing the parameter value of the first attribute parameter of the first URL, whether the first URL is the last URL of the first type registered in the service registration center can be judged, so that the service discovery end can determine the URLs of the same type, and metadata can be generated by all the URLs of the same type.
In one possible design, the attribute values of the first attribute parameters corresponding to the M-1 URLs of the first type respectively buffered before the first URL arrives at the service registration discovery module indicate that the service registration discovery module buffers the corresponding URL, the first URL is the mth URL of the first type arriving at the service registration discovery module, the attribute values of the first attribute parameters of the first URL indicate that the service registration discovery module generates metadata between the first URL and the first URL of the first type buffered before the first URL arrives at the service registration discovery module, M is a positive integer greater than or equal to 2, or the first URL is the nth URL of the first type arriving at the service registration discovery module, N < M, N is a positive integer, and the attribute values of the first attribute parameters of the first URL indicate that the service registration discovery module buffers the first URL.
By adopting the design, by analyzing the parameter value of the first attribute parameter of the first URL, whether the first URL is the last URL in M URLs of the first type can be judged, and further metadata can be generated by the service discovery terminal through a plurality of URLs of the same type.
In one possible design, when the attribute value of the first attribute parameter of the first URL is a first preset value, the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module caches the first URL, and when the attribute value of the first attribute parameter of the first URL is a second preset value, the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module generates metadata between the first URL and a first type of URL cached before the first URL reaches the service registration discovery module, wherein the first preset value is different from the second preset value.
In one possible design, the first attribute parameter is an attribute parameter of a new string type in a service profile of the system.
In one possible design, the first type is a service provider or a service consumer.
In one possible design, the first URL is obtained by parsing a first object, where the first object is at least one of an XML document, an interface definition profile, an API, and an annotation.
In a second aspect, an embodiment of the present application provides a Apache Dubbo system, where the system includes a client and a service registry, where the client includes a service configuration module and a service registry discovery module, where the service configuration module is configured to parse a first object to generate a plurality of URLs, configure an attribute value of a first attribute parameter for each URL in the plurality of URLs, and sequentially input the configured plurality of URLs to the service registry discovery module; the service discovery module is used for analyzing a first URL, determining that the first URL is a first type URL and an attribute value of a first attribute parameter of the first URL, wherein the first URL is any one URL among the configured plurality of URLs, caching the first URL when the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module caches the first URL, generating metadata by the service registration discovery module when the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module generates the metadata by the first URL and the first type URL cached before the first URL reaches the service registration discovery module, generating the metadata by the first URL and the first type URL cached before the first URL reaches the service registration discovery module, and sending the metadata to a service registration center, wherein the service registration center is used for obtaining the metadata by the service registration center and the first type URL cached before the first URL reaches the service registration discovery module.
In one possible design, the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module caches the first URL when the first URL is not the last URL of the first type registered with the service registration center, and indicates that the service registration discovery module generates metadata with the first type of URL cached before the first URL reaches the service registration discovery module when the first URL is the last URL of the first type registered with the service registration center.
In one possible design, the attribute values of the first attribute parameters corresponding to the M-1 URLs of the first type respectively buffered before the first URL arrives at the service registration discovery module indicate that the service registration discovery module buffers the corresponding URL, the first URL is the mth URL of the first type arriving at the service registration discovery module, the attribute values of the first attribute parameters of the first URL indicate that the service registration discovery module generates metadata between the first URL and the first URL of the first type buffered before the first URL arrives at the service registration discovery module, M is a positive integer greater than or equal to 2, or the first URL is the nth URL of the first type arriving at the service registration discovery module, the attribute values of the first attribute parameters of the first URL indicate that the service registration discovery module buffers the first URL, and N < M, N is a positive integer.
In one possible design, when the attribute value of the first attribute parameter of the first URL is a first preset value, the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module caches the first URL, and when the attribute value of the first attribute parameter of the first URL is a second preset value, the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module generates metadata between the first URL and a first type of URL cached before the first URL reaches the service registration discovery module, wherein the first preset value is different from the second preset value.
In one possible design, the first attribute parameter is an attribute parameter of a character string type newly added in a service configuration file of the system, and the service configuration module is used for configuring an attribute value of the first attribute parameter for each URL in the plurality of URLs based on the service configuration file.
In one possible design, the first type is a service provider or a service consumer.
In one possible design, the first object is at least one of an XML document, an interface definition profile, an API, an annotation.
It should be understood that the technical effects of the second aspect and the respective designs in the second aspect may refer to the technical effects of the first method and the respective designs in the first aspect, and the repetition is omitted.
In a third aspect, the present application also provides an apparatus, including a processor and a memory, where the memory is configured to store computer-executable instructions, and where the processor is configured to execute the computer-executable instructions stored in the memory, to cause the communications apparatus to perform the method of the first aspect.
In a fourth aspect, the present application also provides an apparatus comprising a processor and interface circuitry for receiving code instructions and transmitting to the processor, the processor executing the code instructions to perform the method of the first aspect described above.
In a fifth aspect, the present application provides a chip coupled to a memory in an electronic device such that the chip, when run, invokes program instructions stored in the memory to perform the method of the first aspect.
In a sixth aspect, the present application also provides a readable storage medium storing instructions that, when executed, cause the method of the first aspect described above to be carried out.
In a seventh aspect, the application also provides a computer program product comprising a program which, when run on a computer, causes the computer to perform the method of the first aspect described above.
Detailed Description
Embodiments of the present application are described below with reference to the accompanying drawings.
Apache Dubbo is a high performance open source Java RPC distributed service framework. The core functions of Apache Dubbo include interface-oriented remote procedure calls, cluster fault tolerance and load balancing, and service automatic registration and discovery. Apache Dubbo use a hierarchical architecture model to enable maximum decoupling between the various layers, abstracting the service into two roles, service provider (service) and service consumer (reference). Wherein the service provider registers its own service with the service registry. The service consumer subscribes to the service from the service registry, which returns an address list of the service provider to the service consumer. The service consumer selects one service provider from the returned address list to call, and if the call fails, selects another service provider to call.
To solve the problem of low service registration and discovery efficiency due to a rapid increase in communication with a service registration center in a short time. The embodiment of the present application is applied to a Apache Dubbo system, as shown in fig. 2, which includes a client 210 and a service registry 220, wherein the client 210 includes a service registration discovery module 211 and a service configuration module 212, and the type of the client 210 may be a service provider or a service consumer.
The service configuration module 212 is configured to parse the first object to generate a plurality of uniform resource locators (uniform resource locator, URLs), configure an attribute value of the first attribute parameter for each URL in the plurality of URLs, and sequentially input the configured plurality of URLs to the service registration discovery module 211.
The service registration discovery module 211 is configured to parse the first URL, determine that the first URL is a first type of URL and an attribute value of a first attribute parameter of the first URL, and store the first URL in a cache when the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module 211 stores the first URL, and store the first URL in a cache before the first URL reaches the service registration discovery module 211 and send metadata to the service registration center 220 when the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module 211 stores the first URL in a cache before the first URL reaches the service registration discovery module 211.
The service registry 220 is configured to parse the metadata to obtain the first URL and the first type of URL cached before the first URL reaches the service registry discovery module 211.
It should be appreciated that the number of service registries 220 may be one or more. Thus, the plurality of URLs that generate metadata are the same type of URL registered to the same service registry. In addition, embodiments of the present application are not limited in how service registry 220 parses and processes metadata.
The first attribute parameter is an attribute parameter of a character string type newly added in a service configuration file of the system. Illustratively, the service configuration file is dubbo.xsd, and the first attribute parameter may be configured by modifying the dubbo.xsd to serviceType and REFERENCETYPE, for example, the first attribute parameter may be last, and the default value of the first attribute parameter may be "false".
Illustratively, the following is a partial code included in dubbo.xsd, the first attribute parameter may be newly added based on the following format.
Further, the service configuration module 212 configures an attribute value of the first attribute parameter for each URL of the plurality of URLs according to the service configuration file.
Wherein the first type is a service provider or a service consumer. The first object is at least one of an extensible markup language (extensible markup language, XML) document, an interface definition configuration file (-ddubbo.properties.file), an application program interface (application programming interface, API), an annotation. It should be understood that the possible forms of the first object described above are only examples and are not intended to limit the present application.
The interface definition configuration file and the XML are text documents, which means that the file formats are different, and both can be used for analyzing the URL.
Example 1 the following is part of the code included in XML, by which the application name is demo-provider (i.e. the first type is the service provider), and the registration address, protocol name and port number are known.
<dubbo:application name="demo-provider"/>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<dubbo:protocol name="dubbo"port="20890"/>
Example 2 the following is part of the code included in XML, by which the application name is demo-consumer (i.e. the first type is the service consumer), and the registration group and address are known.
<dubbo:application name="demo-consumer"/>
<dubbo:registry group="aaa"address="zookeeper://127.0.0.1:2181"/>
It should be appreciated that in the Apache Dubbo system, the client may also include other modules to implement other functions of the Apache Dubbo system, as the application is not limited in this regard.
Further, as shown in fig. 3, an embodiment of the present application provides a service registration method, which is applied to Apache Dubbo systems, and the method includes:
step 300, the service registration discovery module obtains a first URL.
In step 310, the service registration discovery module parses the first URL, and determines that the first URL is a URL of a first type and an attribute value of a first attribute parameter of the first URL. The service registration discovery end executes step 320A when determining that the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module caches the first URL, and executes step 320B when the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module generates metadata between the first URL and the first type of URL cached before the first URL reaches the service registration discovery module.
Step 320A. When the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module caches the first URL, the service registration discovery module caches the first URL.
The service registration discovery module continues to obtain other URLs and repeats steps 300 and 310.
Step 320B. When the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module generates metadata for the first URL with the first type of URL cached before the first URL reaches the service registration discovery module, the service registration discovery module generates metadata for the first URL with the first type of URL cached before the first URL reaches the service registration discovery module.
And 330, the service registration discovery end sends metadata to the service registration center.
The design of the attribute value of the first attribute parameter of the first URL may include, but is not limited to, the following two ways:
in one possible design, the attribute value of the first attribute parameter of the first URL indicates that the service registration discovery module caches the first URL when the first URL is not the last URL of the first type registered with the service registry. When the first URL is the last URL of the first type registered with the service registry, the attribute value of the first attribute parameter of the first URL instructs the service registry discovery module to generate metadata for the first URL with the first type of URL cached before the first URL reaches the service registry discovery module.
By adopting the design, by analyzing the parameter value of the first attribute parameter of the first URL, whether the first URL is the last URL of the first type registered in the service registration center can be judged, so that the service discovery end can determine the URLs of the same type, and metadata can be generated by all the URLs of the same type.
Illustratively, only one URL of the first type registered with the same service registry is the last URL of the first type registered with the service registry, and the attribute value of the first attribute parameter of the URL indicates that the service registry discovery module generates metadata for the first URL with the first type of URL cached before the first URL reaches the service registry discovery module, and the attribute value of the first attribute parameter of the first type of URL cached before the first URL reaches the service registry discovery module indicates that the service registry discovery module caches the corresponding URL.
In another possible design, the attribute values of the first attribute parameters corresponding to the M-1 URLs of the first type respectively buffered before the first URL arrives at the service registration discovery module indicate that the service registration discovery module buffers the corresponding URL, the first URL is the first URL of the first type arriving at the service registration discovery module, the attribute values of the first attribute parameters of the first URL indicate that the service registration discovery module generates metadata with the first URL and the first URL of the first type buffered before the first URL arrives at the service registration discovery module, M is a positive integer greater than or equal to 2, or the first URL is the first URL of the first type arriving at the service registration discovery module, N < M, N is a positive integer, and the attribute values of the first attribute parameters of the first URL indicate that the service registration discovery module buffers the first URL.
By adopting the design, by analyzing the parameter value of the first attribute parameter of the first URL, whether the first URL is the last URL in M URLs of the first type can be judged, and further metadata can be generated by the service discovery terminal through a plurality of URLs of the same type.
For example, when the value of M is 100, the attribute value of the first attribute parameter corresponding to the 1 st URL indicates that the service registration discovery module caches the 1 st URL, the attribute value of the first attribute parameter corresponding to the 2 nd URL indicates that the service registration discovery module caches the 2 nd URL, the..the..the., the attribute value of the first attribute parameter corresponding to the 99 th URL indicates that the service registration discovery module caches the 99 th URL, and the 100 st URL indicates that the service registration discovery module generates metadata from the cached 99 URLs of the first type and the 100 URLs of the first type.
In addition, the value of M can be changed according to the requirements of users, the actual URL number and other conditions. For example, when the initial value of M is 100, the attribute values of the first attribute parameters corresponding to the 1 st URL of the first type to the 99 th URL of the first type respectively indicate that the service registration discovery module caches the corresponding URLs of the first type, and the 100 th URL of the first type indicates that the service registration discovery module generates metadata from the cached 99 URLs of the first type and the 100 th URL of the first type. If the URLs to be registered are rapidly increased in a short time, the value of M may be adjusted, for example, the value of M may be adjusted to 1000, and then the attribute values of the first attribute parameters corresponding to the 1 st to 999 st URLs indicate that the service registration discovery module caches the corresponding URLs of the first type, and the 1000 st URL indicates that the service registration discovery module generates metadata from the cached 999 URLs of the first type and the 1000 st URL of the first type.
Furthermore, when m=1, the above design is also compatible with prior art solutions.
It should be appreciated that in addition to the attribute value of the first attribute parameter indicating that the service registry discovery module generates metadata for the first URL with the first type of URL cached before the first URL arrives at the service registry discovery module, the first URL and the first type of URL cached before the first URL arrives at the service registry discovery module also need to satisfy the URL that is addressed to the same service registry.
Further, when the attribute value of the first attribute parameter of the first URL is a first preset value, the attribute value of the first attribute parameter of the first URL indicates the service registration discovery module to cache the first URL. When the attribute value of the first attribute parameter of the first URL is a second preset value, the attribute value of the first attribute parameter of the first URL instructs the service registration discovery module to generate metadata between the first URL and the first type of URL cached before the first URL reaches the service registration discovery module. Wherein the first preset value is different from the second preset value.
For example, the first attribute parameter may be last, and the default value of the first attribute parameter may be "false", that is, the first preset value is "false", and the second preset value is "true".
In one example, when the first URL is not the last URL of the first type registered with the service registry, the attribute value of the last attribute of the first URL is a default value of "false". When the first URL is the last URL of the first type registered to the service registry, the last attribute of the first URL has an attribute value of "true".
In another example, when the first URL is an nth URL of the first type to the service registration discovery module, N < M, the attribute value of the last attribute of the first URL is a default value of "false". When the first URL is an mth URL of the first type reaching the service registration discovery module, an attribute value of a last attribute of the first URL is "true".
It should be understood that the first preset value and the second preset value are only examples, and other preset values are also possible, which is not limited by the present application.
Therefore, by adopting the method, the waiting time of the service queue can be reduced, the service registration and discovery efficiency can be improved, the network congestion condition can be relieved, and the problem that the service registration and discovery efficiency is lower due to rapid increase of communication with the service registration center in a short time can be solved by sending a plurality of URL generation metadata of the same type to the service registration center.
As shown in fig. 4 and 5, in the following examples, URLs of N1 service provider types and URLs of N2 service consumer types are obtained by the service configuration module, and N1 and N2 are positive integers, and N1 may be equal to N2 or N1 may not be equal to N2, assuming that one service registry exists.
S401, modifying Apache Dubbo a service configuration file (dubbo.xsd), and adding a character string type attribute last for the service provider type and the service consumer type, wherein the default value of the attribute is 'false'.
Illustratively, an administrator may actively modify Apache Dubbo the service profile (dubbo.xsd).
S402, the service configuration module obtains a plurality of URLs by analyzing at least one of XML, -Ddubbo.properties.file, API and annotation provided by Apache Dubbo, and configures last attribute for each URL.
S403, the service configuration module sequentially inputs the configured plurality of URLs to the service registration discovery module.
S404, the service registration discovery module analyzes the attribute value of the last attribute of each URL input by the service configuration module and judges whether the attribute value of the last attribute of the URL is true. If it is determined that the last attribute of the URL has an attribute value of "true", S406 is executed, otherwise S405 is executed.
S405, when the last attribute of the URL has an attribute value of "false", the service registration discovery module caches the URL classification.
And returning to S404, the service registration discovery module continues to parse the attribute values of last attributes of other URLs input by the service configuration module.
And S406, when the attribute value of the last attribute of the URL is true, the service registration discovery module generates metadata according to the cached URL which is the same as the URL in type and the URL.
Illustratively, as shown in FIG. 5, URLs of N1 service provider types are generated into service provider metadata, and URLs of N2 service consumer types are generated into service consumer metadata.
And S407, the service registration discovery module sends the metadata to the service registration center.
And S408, the service registry receives and analyzes the metadata and stores the analyzed result.
Wherein the service registry can obtain the cached URL and the URL which are the same type as the URL by parsing the metadata.
The embodiments of the present application also provide a computer-readable storage medium storing a computer program that, when run on a computer, causes the computer to perform the methods shown in the above embodiments.
The method provided by the embodiment of the application can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present application, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, a network device, a user device, or other programmable apparatus. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by a wired (e.g., coaxial cable, fiber optic, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (digital video disc, DVD)), or a semiconductor medium (e.g., solid state disk Solid STATE DISK SSD), etc.
The foregoing embodiments are merely used to describe the technical solution of the present application in detail, but the descriptions of the foregoing embodiments are only used to help understand the method of the embodiments of the present application and should not be construed as limiting the embodiments of the present application. Variations or alternatives readily apparent to those skilled in the art are intended to be encompassed within the scope of the embodiments of the present application.