CN115576713A - GRPC service application method and device based on class library - Google Patents

GRPC service application method and device based on class library Download PDF

Info

Publication number
CN115576713A
CN115576713A CN202211223355.8A CN202211223355A CN115576713A CN 115576713 A CN115576713 A CN 115576713A CN 202211223355 A CN202211223355 A CN 202211223355A CN 115576713 A CN115576713 A CN 115576713A
Authority
CN
China
Prior art keywords
service
target
target service
application
grpc
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211223355.8A
Other languages
Chinese (zh)
Inventor
叶大江
黄主斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Clinbrain Information Technology Co Ltd
Original Assignee
Shanghai Clinbrain Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Clinbrain Information Technology Co Ltd filed Critical Shanghai Clinbrain Information Technology Co Ltd
Priority to CN202211223355.8A priority Critical patent/CN115576713A/en
Publication of CN115576713A publication Critical patent/CN115576713A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses a GRPC service application method and device based on a class library. The method is applied to a service provider and comprises the following steps: acquiring a target processing class library, a target service application and a target application protocol file of the target service application, which are provided by a service provider; determining target service parameters of the target service based on the target application protocol file and the target processing class library; the target service is a service generated when the target service application is operated; generating a target service interface protocol corresponding to the target service based on the target service parameters and a preset mapping dictionary; generating a GRPC service corresponding to the target service based on the target service application, the target service parameters and the target processing class library; the GRPC service is used for responding to a GRPC calling request sent by an external service calling end based on a target application protocol file or a target service interface protocol, so that the operation processes of generation and calling of the GRPC service are simplified, and the service calling efficiency is improved.

Description

GRPC service application method and device based on class library
Technical Field
The invention relates to the technical field of computer application, in particular to a GRPC service application method and device based on a class library.
Background
With the increasing abundance of software products, the capability reuse among software products is more and more important, and in order to achieve the capability reuse among cross-language programming products, GRPC service needs to be introduced.
The proto file is generated by combing service implementation logic according to service application source codes, and other products are introduced first when in use.
Firstly, plug-ins or other software needs to be installed or used on IDE of a calling party and a called party to realize the compiling of proto files, and the operation is complex; secondly, the proto file and the manual maintenance proto file need to be manually written by a developer, so that the cost is high and the workload is large; third, proto files cannot be updated hot, and maintenance is difficult; the above problem increases the operation difficulty of the GRPC service in the calling process, thereby reducing the calling efficiency.
Disclosure of Invention
The invention provides a GRPC service application method and device based on a class library, which aim to solve the problem that the GRPC service is difficult to operate in the calling process in the prior art, so that the service calling efficiency is reduced, simplify the generation and calling operation processes of the GRPC service and improve the service calling efficiency.
In a first aspect, an embodiment of the present invention provides a method for applying a GRPC service based on a class library, where the method is applied to a service provider and includes:
acquiring a target processing class library, a target service application and a target application protocol file of the target service application, which are provided by the service provider;
determining target service parameters of target services based on the target application protocol file and the target processing class library; the target service is a service generated when the target service application is operated;
generating a target service interface protocol corresponding to the target service based on the target service parameter and a preset mapping dictionary; the target service interface protocol is used for calling the target service by calling application of an external service calling end;
generating a GRPC service corresponding to the target service based on the target service application, the target service parameter and the target processing class library; the GRPC service is used for responding to a GRPC calling request sent by the external service calling terminal based on the target application protocol file or the target service interface protocol.
Optionally, before the obtaining of the target processing class library provided by the service provider, the method further includes:
acquiring a first source code and a second source code; the first source code comprises a source code for acquiring the target service parameter, and the second source code comprises a source code for converting the target service application into the GRPC service;
and generating the target processing class library based on the first source code and the second source code.
Optionally, the determining target service parameters of the target service based on the target application protocol file and the target processing class library includes:
and analyzing the target application protocol file based on the first source code to obtain the target service parameter.
Optionally, the generating a GRPC service corresponding to the target service based on the target service application, the target service parameter, and the target processing class library includes:
acquiring a GRPC service dependence package for generating the GRPC service;
and generating the GRPC service corresponding to the target service based on the GRPC service dependency package, the target service application, the target service parameter and the second source code.
Optionally, the preset mapping dictionary stores parameter mapping relationships between service parameters of different development languages and protocol standard parameters for generating a service interface protocol;
the generating a target service interface protocol corresponding to the target service based on the target service parameter and a preset mapping dictionary comprises:
determining a development language of the target service application, and determining a target protocol standard parameter corresponding to the target service parameter based on the development language and the parameter mapping relation;
and generating a target service interface protocol corresponding to the target service based on the target protocol standard parameters.
In a second aspect, an embodiment of the present invention further provides a class library-based GRPC service application method, where the method is applied to a service invocation end, and includes:
determining a target service application corresponding to a target service under the condition that the target service to be called of a calling application is provided for a service application of an external service provider;
judging whether the development languages of the calling application and the target service application are the same or not;
if yes, acquiring a target application protocol file of the target service application, and generating a GRPC service client corresponding to the target service based on the target application protocol file and a preset target processing class library;
if not, acquiring a target service interface protocol corresponding to the target service, and generating a GRPC service client corresponding to the target service based on the target service interface protocol, a preset mapping dictionary and a preset GRPC service dependency package;
and generating a GRPC calling request for the target service based on the GRPC service client, and sending the GRPC calling request to the service provider to realize service calling.
Optionally, the generating a GRPC service client corresponding to the target service based on the target application protocol file and a preset target processing class library includes:
determining target service parameters of the target service based on the target application protocol file and the target processing class library;
and generating the GRPC service client corresponding to the target service based on the target service parameter and the target processing class library.
Optionally, the generating a GRPC service client corresponding to the target service based on the target service interface protocol, a preset mapping dictionary, and a preset GRPC service dependency package includes:
compiling the target service interface protocol, and obtaining calling service parameters of the target service based on the preset mapping dictionary; the development language corresponding to the calling service parameter is the same as the calling application development language;
and generating the GRPC service client corresponding to the target service based on the calling service parameter and the GRPC service dependent packet.
In a third aspect, an embodiment of the present invention further provides a class library-based GRPC service application apparatus, which is applied to a service provider, and includes:
the data acquisition module is used for acquiring a target processing class library, a target service application and a target application protocol file of the target service application, which are provided by the service provider;
the target service parameter determining module is used for determining target service parameters of the target service based on the target application protocol file and the target processing class library; the target service is a service generated when the target service application is operated;
the target service interface protocol generation module is used for generating a target service interface protocol corresponding to the target service based on the target service parameters and a preset mapping dictionary; the target service interface protocol is used for calling the target service by calling application of an external service calling end;
the GRPC service generation module is used for generating a GRPC service corresponding to the target service based on the target service application, the target service parameter and the target processing class library; the GRPC service is used for responding to a GRPC calling request sent by the external service calling terminal based on the target application protocol file or the target service interface protocol.
In a fourth aspect, an embodiment of the present invention further provides a class library-based GRPC service application apparatus, where the apparatus is applied to a service invocation end, and includes:
the target service application determining module is used for determining a target service application corresponding to a target service to be called when the target service to be called of the calling application is provided for a service application of an external service provider;
the development language determining module is used for judging whether the development languages of the calling application and the target service application are the same or not;
a first GRPC service client generation module, configured to, if yes, obtain a target application protocol file of the target service application, and generate, based on the target application protocol file and a preset target processing class library, a GRPC service client corresponding to the target service;
a second GRPC service client generation module, configured to, if not, obtain a target service interface protocol corresponding to the target service, and generate a GRPC service client corresponding to the target service based on the target service interface protocol, a preset mapping dictionary, and a preset GRPC service dependency package;
and the GRPC calling request generating module is used for generating a GRPC calling request for the target service based on the GRPC service client and sending the GRPC calling request to the service providing end to realize service calling.
In a fifth aspect, an embodiment of the present invention further provides an electronic device, including:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores a computer program executable by the at least one processor, the computer program being executable by the at least one processor to enable the at least one processor to perform the class library based GRPC service application method according to any of the embodiments of the present invention.
In a sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores computer instructions, and the computer instructions are configured to, when executed, enable a processor to implement the class library-based GRPC service application method according to any embodiment of the present invention.
According to the technical scheme of the embodiment of the invention, a target processing class library, a target service application and a target application protocol file of the target service application provided by a service provider are obtained; determining target service parameters of the target service based on the target application protocol file and the target processing class library; the target service is a service generated when the target service application is operated; generating a target service interface protocol corresponding to the target service based on the target service parameters and a preset mapping dictionary; the target service interface protocol is used for calling the target service by calling application of the external service calling terminal; based on the target service application, the target service parameters and the target processing class library, generating a GRPC service corresponding to the target service; the GRPC service is used for responding to a GRPC calling request sent by an external service calling end based on a target application protocol file or a target service interface protocol, the problem that in the prior art, the GRPC service is difficult to operate in the calling process, so that the service calling efficiency is reduced is solved, the operation processes of generation and calling of the GRPC service are simplified, and the service calling efficiency is improved.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present invention, nor do they necessarily limit the scope of the invention. Other features of the present invention will become apparent from the following description.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a flowchart of a method for applying a GRPC service based on a class library according to an embodiment of the present invention;
fig. 2 is a flowchart of a class library-based GRPC service application method according to a second embodiment of the present invention; (ii) a
Fig. 3 is a schematic structural diagram of a class library-based GRPC service application apparatus according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of a class library-based GRPC service application apparatus according to a fourth embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device implementing the class library-based GRPC service application method according to an embodiment of the present invention.
Detailed Description
In order to make those skilled in the art better understand the technical solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without making any creative effort based on the embodiments in the present invention, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
It is understood that before the technical solutions disclosed in the embodiments of the present disclosure are used, the type, the use range, the use scene, etc. of the personal information related to the present disclosure should be informed to the user and obtain the authorization of the user through a proper manner according to the relevant laws and regulations.
For example, in response to receiving a user's active request, prompt information is sent to the user to explicitly prompt the user that the requested operation to be performed would require acquisition and use of personal information to the user. Thus, the user can autonomously select whether to provide personal information to software or hardware such as an electronic device, an application program, a server, or a storage medium that performs the operations of the disclosed technical solution, according to the prompt information.
As an alternative but non-limiting implementation manner, in response to receiving an active request from the user, the manner of sending the prompt information to the user may be, for example, a pop-up window manner, and the prompt information may be presented in a text manner in the pop-up window. In addition, a selection control for providing personal information to the electronic device by the user's selection of "agreeing" or "disagreeing" can be carried in the pop-up window.
It is understood that the above notification and user authorization process is only illustrative and is not intended to limit the implementation of the present disclosure, and other ways of satisfying the relevant laws and regulations may be applied to the implementation of the present disclosure.
It will be appreciated that the data referred to in this disclosure, including but not limited to the data itself, the acquisition or use of the data, should comply with the requirements of the applicable laws and regulations and related regulations.
Example one
Fig. 1 is a flowchart of a class library-based GRPC service application method according to an embodiment of the present invention, where the embodiment is applicable to a case where a service provided by a service provider is called by an external caller, the method may be executed by a class library-based GRPC service application apparatus, the class library-based GRPC service application apparatus may be implemented in a form of hardware and/or software, and the class library-based GRPC service application apparatus may be configured in the service provider. As shown in fig. 1, the method includes:
s110, acquiring a target processing class library, a target service application and a target application protocol file of the target service application, which are provided by a service provider.
In the embodiment of the present invention, the target service application may be understood as an application installed in the service provider, and a corresponding target service may be generated when the service provider runs the target service application. Optionally, the generated target service is used to be called, so as to implement data processing based on the target service. Optionally, the target service may be locally invoked by a target service application installed locally at the service provider and other service applications installed locally, or may be remotely invoked by an invoking application installed at an external service invoking end. Specifically, when the target service is remotely called, the target service needs to be converted into a corresponding GRPC service in advance, so as to implement remote calling by an external calling application. The GRPC service can be understood as a remote service calling method that can implement capability multiplexing between software.
It should be noted that the target service application protocol file may be understood as a declaration file of the target service application. Specifically, the target service application protocol file can be one dll to be encapsulated by each application, and the dll is called by other applications, contains the names, the out-references and the in-references of all services in the target application, but does not contain the specific method logic for realizing the target service. Optionally, this dll may be referred to as a class library or as an interface. Because the target application protocol file has no specific implementation code, the purpose of decoupling service and declaration can be achieved, and the target service application of the service providing end is convenient to modify the specific service logic in the source code under the condition of not changing the interface (namely the declaration applied by the target service or the target application protocol file), so that the GRPC service can be updated without any operation on the calling application of the calling end. Optionally, if the specific service logic in the source code needs to be changed, the service name or the exit and entry references contained in the dll needs to be changed, the original target application protocol file needs to be replaced by the changed target application protocol file, that is, the hot update of the target application GRPC service can be realized through the direct replacement of the dll file, the maintenance update cost is reduced, and the convenience is improved.
It should also be noted that. DLL (ynamic Link library) can also be expressed as DLL. Specifically, a DLL is a library that contains code and data that can be used by multiple programs simultaneously. The DLL can more easily apply updates to individual modules without affecting other parts of the program. For example, a payroll program, and tax rates change each year. When these changes are isolated into the DLL, the updates can be applied without regenerating or installing the entire program.
It should also be noted that a class library may be understood as a collection of comprehensive object-oriented reusable types, including: interfaces, abstract classes, and concrete classes. Class libraries can address a range of common programming tasks (including tasks such as string management, data collection, database connectivity, and file access), as well as a variety of specialized development tasks (desktop applications, WEB applications, console applications, etc.). Accordingly, the target processing class library may be understood as a class library provided by the service end in the embodiment for converting the target service into the GRPC service.
Optionally, the method for generating the target processing class library in this embodiment may include: acquiring a first source code and a second source code; the first source code comprises a source code for acquiring target service parameters, and the second source code comprises a source code for converting target service application into GRPC service; and generating a target processing class library based on the first source code and the second source code.
Specifically, the source code for acquiring the target service parameter and the source code for converting the target service application into the GRPC service are encapsulated in a preset dll. Since these source codes do not need to be modified, they are encapsulated to obtain the target processing class library in this embodiment.
And S120, determining target service parameters of the target service based on the target application protocol file and the target processing class library.
In the embodiment of the present invention, the target service parameter of the target service may include, but is not limited to, a service name of the target service and corresponding parameters such as an entry parameter, an exit parameter, and a service development language. Optionally, in this embodiment, determining the target service parameter of the target service based on the target application protocol file and the target processing class library includes: and analyzing the target application protocol file based on the first source code to obtain the target service parameters.
The first source code can be understood as a source code for acquiring a target service parameter by a reflection technology; of course, the first source code may also be a source code that acquires the target service parameter through other technologies, and the technology for acquiring the target service parameter is not limited in this embodiment.
And S130, generating a target service interface protocol corresponding to the target service based on the target service parameters and the preset mapping dictionary.
In the embodiment of the invention, the target service interface protocol is used for calling the target service by the calling application of the external service calling terminal. Further, the target service interface protocol may be understood as a protocol file for providing an interface for a calling application of an external service calling terminal of a different development language from the target service application so as to call the target service generated by the target service application. For example, if the target service application is an application developed in C # language, and the calling application is an application developed in Java language, when the calling application calls a service generated by the target service application, the calling application developed in Java language needs to identify a target service and a calling method thereof of the target service application developed in C # language according to a target service interface protocol, and generate a calling request based on the calling method of the target service, so that the calling application can correctly call the target service provided by the target service application.
It should be noted that the target service interface protocol may be understood as a proto file for generating an interface for invoking a GRPC service. Because the proto file in the prior art needs to be written manually, the coding mode is as follows: the proto file is written first, and then the empty method body is obtained through compiling, and old service source code business logic needs to be integrated into the empty method body to be achieved. The technical scheme of the embodiment adopts a new method, namely a Grpc Code First mode, specifically a writing method, and then directly converts the Grpc Code First mode into GRPC service based on the method. The proto file is automatically generated without copying a source code and a developer does not need to card business logic and learn the coding specification of the proto file, so that the workload of the developer is reduced, the operation procedures of generation and calling of GRPC service are simplified, and the service calling efficiency is improved.
In this embodiment, the preset mapping dictionary stores parameter mapping relationships between service parameters of different development languages and protocol standard parameters for generating the service interface protocol. Correspondingly, the method for generating the target service interface protocol in this embodiment may include: determining a development language of the target service application, and determining a target protocol standard parameter corresponding to the target service parameter based on the development language and the parameter mapping relation; and generating a target service interface protocol corresponding to the target service based on the target protocol standard parameters.
The development language may include, but is not limited to, java, C + +, C #, python, and the like. The protocol standard parameters can be understood as parameters such as interface parameter in and interface parameter out of a service protocol interface corresponding to the GRPC service.
Specifically, the development language of the target service application is determined, for example, C # language. Determining a corresponding relation between a service parameter of the C # language and a protocol standard parameter of the GRPC service in a preset mapping dictionary, determining a target protocol standard parameter of the GRPC service based on the corresponding relation and a target service parameter written by the C # language, and generating a target service interface protocol based on the target protocol standard parameter so as to realize that the target service application is used when being called by an external calling application different from the development language of the target service application.
And S140, generating the GRPC service corresponding to the target service based on the target service application, the target service parameter and the target processing class library.
In the embodiment of the present invention, the GRPC service is configured to respond to a GRPC call request sent by an external service call end based on a target application protocol file or a target service interface protocol.
Optionally, in this embodiment, the method for generating a GRPC service corresponding to a target service based on a target service application, a target service parameter, and a target processing class library may include: acquiring a GRPC service dependence package for generating GRPC service; and generating the GRPC service corresponding to the target service based on the GRPC service dependent packet, the target service application, the target service parameter and the second source code.
The GRPC service dependent packet may be a data packet for generating a GRPC. Specifically, a GRPC service dependent packet is acquired. Optionally, the source code may be obtained based on a second source code pre-stored in the target processing class library; of course, the GRPC service dependency package may also be obtained based on a database stored in advance in a separate database. In this embodiment, the GRPC service dependency package is stored in advance in an independent database, so that the size of the target processing class library can be reduced, and the storage space of the target class library can be saved.
Specifically, a target service application source code of the target service, the target service parameter, and data in the GRPC service dependency packet are substituted into the second source code to obtain a GRPC service corresponding to the target service.
According to the technical scheme of the embodiment of the invention, a target processing class library, a target service application and a target application protocol file of the target service application provided by a service provider are obtained; determining target service parameters of the target service based on the target application protocol file and the target processing class library; the target service is a service generated when the target service application is operated; generating a target service interface protocol corresponding to the target service based on the target service parameters and a preset mapping dictionary; the target service interface protocol is used for calling the target service by calling application of the external service calling terminal; based on the target service application, the target service parameters and the target processing class library, generating a GRPC service corresponding to the target service; the GRPC service is used for responding to a GRPC calling request sent by an external service calling end based on a target application protocol file or a target service interface protocol, the problem that in the prior art, the GRPC service is difficult to operate in the calling process, so that the service calling efficiency is reduced is solved, the operation processes of generation and calling of the GRPC service are simplified, and the service calling efficiency is improved.
Example two
Fig. 2 is a flowchart of a class library-based GRPC service application method according to a second embodiment of the present invention, where the method may be executed by a class library-based GRPC service application apparatus, the class library-based GRPC service application apparatus may be implemented in a form of hardware and/or software, and the class library-based GRPC service application apparatus may be configured in a service invocation end. As shown in fig. 2, the method includes:
s210, determining the target service application corresponding to the target service under the condition that the target service to be called by the calling application is provided for the service application of the external service provider.
In the embodiment of the present invention, the calling application may be understood as an application terminal that needs to process data based on a service. Accordingly, the target service may be a service for processing data in the calling application. Optionally, the target service called by the calling application may be a service provided by the local end, or a service provided by the external service providing end.
Specifically, the method for determining that the target service is provided for the service application of the external service provider may include performing service lookup at a service invocation end where the invocation application is located. If the search result is present, the target service is the service provided by the local end; otherwise, if the service application does not exist, determining that the target service is the service provided by the service application of the external service provider.
Specifically, in the case that the target service is determined to be provided for the service application of the external service provider based on the above manner, the target service application corresponding to the target service is determined. Wherein a target service application may be understood as an application that generates a target service. In other words, the corresponding target service may be generated when the service provider runs the target service application. And the generated target service is used for being called by the calling application so as to realize that the calling application carries out data processing based on the target service.
S220, judging whether the development languages of the calling application and the target service application are the same.
In embodiments of the present invention, the development language may include, but is not limited to, java, C + +, C #, python, and the like.
Specifically, the development language of the calling application and the development language of the target service application are respectively obtained, the development languages of the two applications may be determined based on the application protocol files of the two applications, or may be determined based on other manners, which is not limited herein. Optionally, the development languages of the two applications are compared. If the comparison result is consistent, step S230 is executed; otherwise, if the comparison result is not consistent, step S240 is executed.
And S230, acquiring a target application protocol file corresponding to the target service application, and generating a GRPC service client corresponding to the target service based on the target application protocol file and a preset target processing class library.
In the embodiment of the invention, if the development languages of the calling application and the target service application are judged to be the same, namely the calling application and the target service application are written in the same development language, the service parameters can be directly identified with each other.
On this basis, the method for generating the GRPC service client corresponding to the target service in this embodiment may include: determining target service parameters of the target service based on the target application protocol file and the target processing class library; and generating a GRPC service client corresponding to the target service based on the target service parameters and the target processing class library.
Specifically, the target application protocol file is analyzed based on the first source code to obtain the target service parameter. And acquiring a GRPC service dependency package for generating the GRPC service client, and generating the GRPC service client corresponding to the target service based on the GRPC service dependency package, the target service parameter and the second source code.
In this embodiment, in an environment where the calling application and the target service application are in the same development language, the calling application and the target service application do not need to perform any learning or writing operation, and only the target processing class library needs to be integrated with the source codes of the calling application and the target service application. Optionally, the target processing class library and the application source code may be placed in a folder, or a part of or all of the code of the target processing class library may be integrated into the application source code, or both of them may be integrated. The target service provided by the target service application can be automatically converted into the GRPC service through the arrangement, and the GRPC service client corresponding to the target service can be automatically generated by calling the application, and the GRPC service generated by the providing end can be directly called.
S240, acquiring a target service interface protocol of the target service, and generating a GRPC service client corresponding to the target service based on the target service interface protocol, the preset mapping dictionary and the preset GRPC service dependency package.
In the embodiment of the invention, if the development languages of the calling application and the target service application are different, the calling application and the target service application are stated to be obtained by compiling different development languages, and the service parameters cannot be directly identified with each other.
On this basis, the method for generating the GRPC service client corresponding to the target service in this embodiment may include: compiling the target service interface protocol, and obtaining calling service parameters of the target service based on a preset mapping dictionary; calling a development language corresponding to the service parameter to be the same as the calling application development language; and generating a GRPC service client corresponding to the target service based on the calling service parameter and the preset GRPC service dependence package.
Specifically, a target service interface protocol is compiled to obtain a target standard protocol parameter of the called target service; determining a calling service parameter which is the same as the calling application in development language, can be identified by the calling application and corresponds to a target service parameter of a target service based on a preset mapping dictionary and a target standard protocol parameter; and generating a GRPC service client corresponding to the target service based on the calling service parameter and the preset GRPC service dependence package.
In this embodiment, if the target service call between different development languages is implemented, the generated proto is compiled, and based on the GRPC dependency package, the GRPC service client of the target service is automatically generated, so as to implement the service call between different development languages. Although the technical scheme can not completely realize the hot update of the target application, the proto file does not need to be learned, written and edited, the operation is simplified, the learning cost and the upgrading and transforming cost of the existing software application are saved, the operation procedures of the generation and the calling of the GRPC service are simplified, and the service calling efficiency is improved.
And S250, generating a GRPC calling request for the target service based on the GRPC service client, and sending the GRPC calling request to the service provider to realize service calling.
In this embodiment, the GRPC service invocation of the target service application is implemented by sending a GRPC invocation request of the target service to the target service application based on the invocation application.
In the embodiment of the invention, under the condition that the target service to be called by the calling application is provided for the service application of the external service provider, the target service application corresponding to the target service is determined; judging whether the development languages of the calling application and the target service application are the same or not; if yes, acquiring a target application protocol file of the target service application, and generating a GRPC service client corresponding to the target service based on the target application protocol file and a preset target processing class library; if not, acquiring a target service interface protocol of the target service, and generating a GRPC service client corresponding to the target service based on the target service interface protocol, a preset mapping dictionary and a preset GRPC service dependency package; the GRPC service client generates a GRPC calling request for a target service and sends the GRPC calling request to the service provider to realize service calling, so that the problem that the GRPC service is difficult to operate in the calling process in the prior art, and the service calling efficiency is reduced is solved, the operation processes of generation and calling of the GRPC service are simplified, and the service calling efficiency is improved.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a class library-based GRPC service application apparatus according to a third embodiment of the present invention. As shown in fig. 3, the apparatus includes: the system comprises a data acquisition module 310, a target service parameter determination module 320, a target service interface protocol generation module 330 and a GRPC service generation module 340; wherein,
a data obtaining module 310, configured to obtain a target processing class library, a target service application, and a target application protocol file of the target service application, which are provided by the service provider;
a target service parameter determining module 320, configured to determine a target service parameter of a target service based on the target application protocol file and the target processing class library; the target service is a service generated when the target service application is operated;
a target service interface protocol generation module 330, configured to generate a target service interface protocol corresponding to the target service based on the target service parameter and a preset mapping dictionary; the target service interface protocol is used for calling the target service by calling application of an external service calling end;
a GRPC service generation module 340, configured to generate a GRPC service corresponding to the target service based on the target service application, the target service parameter, and the target processing class library; the GRPC service is used for responding to a GRPC calling request sent by the external service calling terminal based on the target application protocol file or the target service interface protocol.
On the basis of the foregoing embodiments, optionally, the apparatus includes:
the source code acquisition module is used for acquiring a first source code and a second source code; the first source code comprises a source code for acquiring the target service parameter, and the second source code comprises a source code for converting the target service application into the GRPC service;
and the target processing class library generating module is used for generating the target processing class library based on the first source code and the second source code.
On the basis of the foregoing embodiments, optionally, the target service parameter determining module 320 includes:
and the service parameter determining unit is used for analyzing the target application protocol file based on the first source code to obtain the target service parameter.
On the basis of the foregoing embodiments, optionally, the GRPC service generating module 340 includes:
a GRPC service dependency package obtaining unit, configured to obtain a GRPC service dependency package for generating the GRPC service;
a GRPC service generating unit, configured to generate the GRPC service corresponding to the target service based on the GRPC service dependent packet, the target service application, the target service parameter, and the second source code.
On the basis of the foregoing embodiments, optionally, the preset mapping dictionary stores a parameter mapping relationship between service parameters of different development languages and protocol standard parameters for generating a service interface protocol;
the target service interface protocol generation module 330 includes:
the protocol standard parameter determining unit is used for determining a development language of the target service application and determining a target protocol standard parameter corresponding to the target service parameter based on the development language and the parameter mapping relation;
and the target service interface protocol generating unit is used for generating a target service interface protocol corresponding to the target service based on the target protocol standard parameters.
The GRPC service application device based on the class library applied to the service provider can execute the GRPC service application method based on the class library applied to the service provider provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
Example four
Fig. 4 is a schematic structural diagram of a class library-based GRPC service application apparatus applied to a service provider according to a fourth embodiment of the present invention. As shown in fig. 4, the apparatus includes: a target service application determining module 410, a development language determining module 420, a first GRPC service client generating module 430 and a second GRPC service client generating module 440; wherein,
a target service application determining module 410, configured to determine a target service application corresponding to a target service to be invoked when determining that the target service to be invoked is provided for a service application of an external service provider;
a development language determining module 420, configured to determine whether the development languages of the calling application and the target service application are the same;
a first GRPC service client generation module 430, configured to, if yes, obtain a target application protocol file of the target service application, and generate, based on the target application protocol file and a preset target processing class library, a GRPC service client corresponding to the target service;
a second GRPC service client generation module 440, configured to, if not, obtain a target service interface protocol corresponding to the target service, and generate a GRPC service client corresponding to the target service based on the target service interface protocol, a preset mapping dictionary, and a preset GRPC service dependency package;
and the GRPC calling request generating module is used for generating a GRPC calling request for the target service based on the GRPC service client and sending the GRPC calling request to the service providing end to realize service calling.
On the basis of the foregoing embodiments, optionally, the first GRPC service client generation module 430 includes:
a service parameter determining unit, configured to determine a target service parameter of the target service based on the target application protocol file and the target processing class library;
and the GRPC service generating unit is used for generating the GRPC service client corresponding to the target service based on the target service parameter and the target processing class library.
On the basis of the foregoing embodiments, optionally, the second GRPC service client generation module 440 includes:
the service parameter determining unit is used for compiling the target service interface protocol and obtaining calling service parameters of the target service based on the preset mapping dictionary;
and the GRPC service generation unit is used for generating the GRPC service client corresponding to the target service based on the calling service parameter and the GRPC service dependency package.
The GRPC service application device based on the class library applied to the service provider can execute the GRPC service application method based on the class library applied to the service provider provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
EXAMPLE five
FIG. 5 illustrates a schematic diagram of an electronic device 10 that may be used to implement an embodiment of the invention. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 5, the electronic device 10 includes at least one processor 11, and a memory communicatively connected to the at least one processor 11, such as a Read Only Memory (ROM) 12, a Random Access Memory (RAM) 13, and the like, wherein the memory stores a computer program executable by the at least one processor, and the processor 11 can perform various suitable actions and processes according to the computer program stored in the Read Only Memory (ROM) 12 or the computer program loaded from a storage unit 18 into the Random Access Memory (RAM) 13. In the RAM 13, various programs and data necessary for the operation of the electronic apparatus 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other via a bus 14. An input/output (I/O) interface 15 is also connected to bus 14.
A number of components in the electronic device 10 are connected to the I/O interface 15, including: an input unit 16 such as a keyboard, a mouse, or the like; an output unit 17 such as various types of displays, speakers, and the like; a storage unit 18 such as a magnetic disk, an optical disk, or the like; and a communication unit 19 such as a network card, modem, wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information/data with other devices via a computer network such as the internet and/or various telecommunication networks.
The processor 11 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various dedicated Artificial Intelligence (AI) computing chips, various processors running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and so forth. The processor 11 performs the various methods and processes described above, such as the class library-based GRPC service application method.
In some embodiments, the class library-based GRPC service application method may be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 10 via the ROM 12 and/or the communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the class library-based GRPC service application method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured by any other suitable means (e.g. by means of firmware) to execute the class library based GRPC service application method.
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Computer programs for implementing the methods of the present invention can be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions/acts specified in the flowchart and/or block diagram block or blocks to be performed. A computer program can execute entirely on a machine, partly on a machine, as a stand-alone software package partly on a machine and partly on a remote machine or entirely on a remote machine or server.
In the context of the present invention, a computer-readable storage medium may be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. A computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, the computer readable storage medium may be a machine readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the electronic device. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), blockchain networks, and the internet.
The computing system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical host and VPS service are overcome.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present invention may be executed in parallel, sequentially, or in different orders, and are not limited herein as long as the desired results of the technical solution of the present invention can be achieved.
The above-described embodiments should not be construed as limiting the scope of the invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A GRPC service application method based on class library is characterized in that the method is applied to a service provider and comprises the following steps:
acquiring a target processing class library, a target service application and a target application protocol file of the target service application, which are provided by the service provider;
determining target service parameters of target services based on the target application protocol file and the target processing class library; the target service is a service generated when the target service application is operated;
generating a target service interface protocol corresponding to the target service based on the target service parameters and a preset mapping dictionary; the target service interface protocol is used for calling the target service by calling application of an external service calling end;
generating a GRPC service corresponding to the target service based on the target service application, the target service parameters and the target processing class library; the GRPC service is used for responding to a GRPC calling request sent by the external service calling terminal based on the target application protocol file or the target service interface protocol.
2. The method according to claim 1, further comprising, before said obtaining the target processing class library provided by the service provider:
acquiring a first source code and a second source code; the first source code comprises a source code for acquiring the target service parameter, and the second source code comprises a source code for converting the target service application into the GRPC service;
and generating the target processing class library based on the first source code and the second source code.
3. The method of claim 2, wherein determining target service parameters for a target service based on the target application protocol file and the target processing class library comprises:
and analyzing the target application protocol file based on the first source code to obtain the target service parameter.
4. The method of claim 2, wherein the generating the GRPC service corresponding to the target service based on the target service application, the target service parameter, and the target processing class library comprises:
acquiring a GRPC service dependence package for generating the GRPC service;
and generating the GRPC service corresponding to the target service based on the GRPC service dependency package, the target service application, the target service parameter and the second source code.
5. The method according to claim 1, wherein the preset mapping dictionary stores parameter mapping relations between service parameters of different development languages and protocol standard parameters for generating service interface protocols;
generating a target service interface protocol corresponding to the target service based on the target service parameter and a preset mapping dictionary, wherein the generating comprises:
determining a development language of the target service application, and determining a target protocol standard parameter corresponding to the target service parameter based on the development language and the parameter mapping relation;
and generating a target service interface protocol corresponding to the target service based on the target protocol standard parameter.
6. A GRPC service application method based on class library is characterized in that the method is applied to a service calling end and comprises the following steps:
determining a target service application corresponding to a target service under the condition that the target service to be called by a calling application is provided for a service application of an external service provider;
judging whether the development languages of the calling application and the target service application are the same;
if yes, acquiring a target application protocol file of the target service application, and generating a GRPC service client corresponding to the target service based on the target application protocol file and a preset target processing class library;
if not, acquiring a target service interface protocol corresponding to the target service, and generating a GRPC service client corresponding to the target service based on the target service interface protocol, a preset mapping dictionary and a preset GRPC service dependency package;
and generating a GRPC calling request for the target service based on the GRPC service client, and sending the GRPC calling request to the service provider to realize service calling.
7. The method according to claim 6, wherein the generating a GRPC service client corresponding to the target service based on the target application protocol file and a preset target processing class library includes:
determining target service parameters of the target service based on the target application protocol file and the target processing class library;
and generating the GRPC service client corresponding to the target service based on the target service parameter and the target processing class library.
8. The method of claim 6, wherein the generating the GRPC service client corresponding to the target service based on the target service interface protocol, a preset mapping dictionary and a preset GRPC service dependency package comprises:
compiling the target service interface protocol, and obtaining calling service parameters of the target service based on the preset mapping dictionary; the development language corresponding to the calling service parameter is the same as the calling application development language;
and generating the GRPC service client corresponding to the target service based on the calling service parameter and the GRPC service dependent packet.
9. A kind of GRPC service application device based on class library, characterized by that, apply to the service provider, comprising:
the data acquisition module is used for acquiring a target processing class library, a target service application and a target application protocol file of the target service application, which are provided by the service provider;
the target service parameter determining module is used for determining target service parameters of the target service based on the target application protocol file and the target processing class library; the target service is a service generated when the target service application is operated;
the target service interface protocol generation module is used for generating a target service interface protocol corresponding to the target service based on the target service parameters and a preset mapping dictionary; the target service interface protocol is used for calling the target service by calling application of an external service calling end;
the GRPC service generation module is used for generating a GRPC service corresponding to the target service based on the target service application, the target service parameter and the target processing class library; the GRPC service is used for responding to a GRPC calling request sent by the external service calling terminal based on the target application protocol file or the target service interface protocol.
10. A kind of GRPC service application device based on class library, characterized by that, apply to the service call end, comprising:
the target service application determining module is used for determining a target service application corresponding to a target service to be called when the target service to be called of the calling application is provided for a service application of an external service providing end;
the development language determining module is used for judging whether the development languages of the calling application and the target service application are the same or not;
the first GRPC service client generation module is used for acquiring a target application protocol file of the target service application if the target application protocol file is in the positive state, and generating a GRPC service client corresponding to the target service based on the target application protocol file and a preset target processing class library;
a second GRPC service client generation module, configured to, if not, obtain a target service interface protocol corresponding to the target service, and generate a GRPC service client corresponding to the target service based on the target service interface protocol, a preset mapping dictionary, and a preset GRPC service dependency package;
and the GRPC calling request generating module is used for generating a GRPC calling request for the target service based on the GRPC service client and sending the GRPC calling request to the service providing end to realize service calling.
CN202211223355.8A 2022-10-08 2022-10-08 GRPC service application method and device based on class library Pending CN115576713A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211223355.8A CN115576713A (en) 2022-10-08 2022-10-08 GRPC service application method and device based on class library

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211223355.8A CN115576713A (en) 2022-10-08 2022-10-08 GRPC service application method and device based on class library

Publications (1)

Publication Number Publication Date
CN115576713A true CN115576713A (en) 2023-01-06

Family

ID=84585041

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211223355.8A Pending CN115576713A (en) 2022-10-08 2022-10-08 GRPC service application method and device based on class library

Country Status (1)

Country Link
CN (1) CN115576713A (en)

Similar Documents

Publication Publication Date Title
CN113010181B (en) Deployment method and device of operators in deep learning framework and electronic equipment
EP3828701B1 (en) Mini app processing method, server, device and storage medium
US11934287B2 (en) Method, electronic device and computer program product for processing data
CN113934464A (en) Method and device for starting android application in Linux system and electronic equipment
CN110858172A (en) Automatic test code generation method and device
US10554726B1 (en) Remote device drivers for internet-connectable devices
CN113821352A (en) Remote service calling method and device
CN113050940A (en) Method for previewing small program, related device and computer program product
CN112015468A (en) Interface document processing method and device, electronic equipment and storage medium
CN111125064A (en) Method and device for generating database mode definition statement
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
EP3872630A2 (en) Request processing method and apparatus, electronic device, and computer storage medium
CN112860566B (en) Applet detection method, device, electronic equipment and readable medium
CN114443076A (en) Mirror image construction method, device, equipment and storage medium
CN113010174A (en) Service monitoring method and device
CN113076343B (en) Data query method, device, equipment and storage medium
CN115576713A (en) GRPC service application method and device based on class library
CN110599112A (en) Method and device for developing and maintaining network page
CN114218313A (en) Data management method, device, electronic equipment, storage medium and product
CN113779018A (en) Data processing method and device
CN117093638B (en) Micro-service data initialization method, system, electronic equipment and storage medium
CN116775171B (en) Architecture switching method and device, electronic equipment and storage medium
CN118200220A (en) Environment access method, device, gateway and storage medium
CN116166253A (en) Inter-vehicle domain communication method, data gateway, device and storage medium
CN115167847A (en) Application log acquisition method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination