CN106648940B - Remote procedure calling method and device - Google Patents

Remote procedure calling method and device Download PDF

Info

Publication number
CN106648940B
CN106648940B CN201710146522.6A CN201710146522A CN106648940B CN 106648940 B CN106648940 B CN 106648940B CN 201710146522 A CN201710146522 A CN 201710146522A CN 106648940 B CN106648940 B CN 106648940B
Authority
CN
China
Prior art keywords
message
request
client
rpc
client device
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.)
Active
Application number
CN201710146522.6A
Other languages
Chinese (zh)
Other versions
CN106648940A (en
Inventor
陈宝玉
陈连增
夏正伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baiwu Tech Co ltd
Original Assignee
Beijing Baiwu Tech Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baiwu Tech Co ltd filed Critical Beijing Baiwu Tech Co ltd
Priority to CN201710146522.6A priority Critical patent/CN106648940B/en
Publication of CN106648940A publication Critical patent/CN106648940A/en
Application granted granted Critical
Publication of CN106648940B publication Critical patent/CN106648940B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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
    • 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/546Message passing systems or structures, e.g. queues
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/133Protocols for remote procedure calls [RPC]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/541Client-server
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The embodiment of the invention provides a remote procedure call method and a remote procedure call device, which can receive a remote procedure call protocol (RPC) request sent by client equipment; analyzing the RPC request according to a preset RPC protocol to obtain identification information of a method called by the RPC request; determining a method requested to be called by the client equipment, executing the method requested to be called by the client equipment to generate a message corresponding to the method, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message; and selecting a thread from a thread pool to execute the message in the message production queue and feeding back an execution result to the client device. The method can be executed through the identification information of the method requested to be called in the RPC request, so that an IDL file does not need to be generated, and the RPC calling process is simplified.

Description

Remote procedure calling method and device
Technical Field
The invention relates to the technical field of remote procedure call, in particular to a remote procedure call method and a remote procedure call device.
Background
The Remote Procedure Call Protocol (RPC) is a Protocol for requesting a service from a Remote computer program through a network, and adopts a client device/server device mode, in which a party requesting the service is a client device and a party providing the service is a server device.
To support different language platforms, the technician developed a thread. The method solves the problem of large data volume transmission and communication among systems and the difference of language environments among the systems, and has the characteristic of cross-platform. However, the thread Interface specification requires a uniform definition Interface Description Language (IDL) file. Once the interface changes, the IDC file needs to be re-modified.
In the development and design process of a large-scale system, a large number of butt joint processes exist, and the frequency of interface modification is very high, so that the remote process calling by using the Thrift is more complicated.
Disclosure of Invention
The embodiment of the invention aims to provide a remote procedure call method and a remote procedure call device so as to simplify an RPC call procedure. The specific technical scheme is as follows:
a remote procedure call method is applied to a server device, the server device is in communication connection with a client device, and the method comprises the following steps:
receiving a remote procedure call protocol (RPC) request sent by the client equipment;
analyzing the RPC request according to a preset RPC protocol to obtain identification information of a method called by the RPC request;
determining a method requested to be called by the client equipment, executing the method requested to be called by the client equipment to generate a message corresponding to the method, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message;
and selecting a thread from a thread pool to execute the message in the message production queue and feeding back an execution result to the client device.
Optionally, the method further includes:
monitoring the execution result of the thread executing the message in the message production queue;
and judging whether the execution result meets a preset trigger condition, if so, triggering an event matched with the met trigger condition.
Optionally, the preset RPC protocol is:
the format of the RPC request is as follows: packet length, header size, request method signature, message type, sequence number SEQID, extended data length, encoded extended data content, body content length, body data.
Optionally, before receiving the remote procedure call protocol (RPC) request sent by the client device, the method further includes:
the server side equipment monitors a connection request of the client side equipment;
and after monitoring the connection request of the client equipment, establishing a link with the client equipment.
Optionally, the method further includes:
the server side equipment monitors the link state with the client side equipment;
and when the link between the server side equipment and the client side equipment is disconnected, the link with the client side equipment is reestablished.
Optionally, the determining the method requested to be called by the client device, executing the method requested to be called by the client device to generate a message corresponding to the method, and placing the generated message in a message production queue includes:
locally searching a key with the obtained identification information in the server-side equipment, generating a message corresponding to the method according to a method parameter stored in a value corresponding to the key, and putting the generated message into a message production queue;
when the write message is generated, the generated write message is put into a write message production queue;
and when the read message is generated, the generated read message is placed in a read message production queue.
Optionally, the selecting a thread from the thread pool to execute the message in the message production queue and feeding back an execution result to the client device includes:
acquiring a write message in the write message execution production queue from the write message consumer thread pool, and feeding back an execution result to the client device after the write message is successfully executed, wherein the server device puts the thread back to the write message consumer thread pool after the write message is executed by the thread;
and obtaining the read message in the read message production queue executed by the thread from the read message consumer thread pool, and feeding back an execution result to the client device after the read message is successfully executed, wherein the server device puts the thread back to the read message consumer thread pool after the read message is executed by the thread.
Optionally, before the server device listens to the connection request of the client device, the method further includes:
binding a monitoring address TServer socket for monitoring the connection request of the client equipment, and registering an interface method stub RpcProxyprocessor connected with the client equipment;
starting an IO thread, creating a Selector, registering a channel ServerSocketChannel to the Selector to monitor a connection request of a client device, and polling a ready Selector key by the Selector, wherein the Selector is an object identifier of an event registered in the channel ServerSocketChannel when the client device is connected with a server device;
after monitoring the connection request of the client device, establishing a link with the client device includes:
after the connection request of the client device is monitored from the monitoring address TServerSocket, setting a parameter for connecting with the client device sending the connection request by the acceptimipl, and establishing a link with the client device sending the connection request according to the set parameter;
the determining the method called by the client device request, executing the method called by the client device request to generate a message corresponding to the method, and putting the generated message into a message production queue, includes:
and the Selector determines the method requested to be called by the client equipment, executes the method requested to be called by the client equipment to generate a message corresponding to the method, and places the generated message into a message production queue.
A remote procedure call device applied to a server device, wherein the server device is in communication connection with a client device, and the device comprises: the device comprises a request receiving unit, a request analyzing unit, a method executing unit and a message executing unit;
the request receiving unit is used for receiving a remote procedure call protocol (RPC) request sent by the client equipment;
the request analysis unit is used for analyzing the RPC request according to a preset RPC protocol to obtain identification information of a method called by the request in the RPC request;
the method execution unit is used for determining a method requested to be called by the client device, executing the method requested to be called by the client device to generate a message corresponding to the method, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message;
and the message execution unit is used for selecting a thread from a thread pool to execute the message in the message production queue and feeding back an execution result to the client equipment.
Optionally, the preset RPC protocol is:
the format of the RPC request is as follows: packet length, header size, request method signature, message type, sequence number SEQID, extended data length, encoded extended data content, body content length, body data.
The remote procedure call method and the device provided by the embodiment of the invention can receive a remote procedure call protocol (RPC) request sent by the client equipment; analyzing the RPC request according to a preset RPC protocol to obtain identification information of a method called by the RPC request; determining a method requested to be called by the client equipment, executing the method requested to be called by the client equipment to generate a message corresponding to the method, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message; and selecting a thread from a thread pool to execute the message in the message production queue and feeding back an execution result to the client device. The method can be executed through the identification information of the method requested to be called in the RPC request, so that an IDL file does not need to be generated, and the RPC calling process is simplified.
Of course, it is not necessary for any product or method of practicing the invention to achieve all of the above-described advantages at the same time.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a flowchart of a remote procedure call method according to an embodiment of the present invention;
FIG. 2 is a flow chart of another remote procedure call method according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a remote procedure call device according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of another remote procedure call device according to an embodiment of the present invention.
Detailed Description
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 derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1, a remote procedure call method provided in an embodiment of the present invention is applied to a server device, where the server device is in communication connection with a client device, and the method may include:
s100, receiving a remote procedure call protocol (RPC) request sent by the client equipment;
before step S100, the method may further include:
the server side equipment monitors a connection request of the client side equipment;
and after monitoring the connection request of the client equipment, establishing a link with the client equipment.
Specifically, parameters for connecting with the client device may be set by the acceptimipl according to the connection request of the client device to establish a link with the client device.
Further, in order to keep the link with the client device stable, the present invention may further include:
the server side equipment monitors the link state with the client side equipment;
and when the link between the server side equipment and the client side equipment is disconnected, the link with the client side equipment is reestablished.
Because the server-side equipment monitors the link state with the client-side equipment, when the link between the server-side equipment and the client-side equipment is disconnected, the link with the client-side equipment can be reestablished in time to complete corresponding work, and the working efficiency is improved.
In other embodiments of the present invention, the server device may periodically scan all links with each client device, and perform corresponding processing according to the number of links. For example: and setting the minimum link quantity and the maximum link quantity, and recycling the links which are not used in the current link when the current link quantity is greater than the maximum link quantity so as to reduce the current link quantity and save the system overhead caused by excessive link quantity.
The method is suitable for both Java.NIO and standard IO, wherein the same TServer is adopted for the Java.NIO and the standard IO, the Java.NIO starts threads with fixed number to process Java.NIO events according to the number of CPU cores of the server device, and the standard IO can set the minimum thread number and the maximum thread number to process the standard IO events according to actual conditions.
S200, analyzing the RPC request according to a preset RPC protocol to obtain identification information of a method called by the RPC request;
the identification information of the method may be: the method signature is requested.
The preset RPC protocol can be as follows:
the format of the RPC request is as follows: packet length, header size, request method signature, message type, sequence number SEQID, extended data length, encoded extended data content, body content length, body data.
Header data in the form of KEY ═ VALUE is stored in the tmessage.name of the header of the RPC request. The packet header comprises a request method signature, a message type, a sequence number SEQID, an extended data length and encoded extended data content; wherein the request method signature consists of the name of the requested method and a list of parameters. SEQID is used for identifying different RPC requests, and the encoded extended data content is used for storing the request and the response content. The message type is a type of remote method call, and includes four types: CALL (service CALL), EXCEPTION (EXCEPTION handling), REPLY (request response), and ONEWAY (extended use). The extension data is mainly used for other data transmission and method calling except service data, and can also be used for method call-back.
S300, determining a method requested to be called by the client equipment, executing the method requested to be called by the client equipment to generate a message corresponding to the method, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message;
specifically, since the server device may be in communication connection with a plurality of client devices, the server device often needs to process a plurality of concurrent RPC requests, and in this case, the concurrent RPC requests may be processed in the message production queue.
Wherein, step S300 may specifically include:
locally searching a key with the obtained identification information in the server-side equipment, generating a message corresponding to the method according to a method parameter stored in a value corresponding to the key, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message;
when the write message is generated, the generated write message is put into a write message production queue;
and when the read message is generated, the generated read message is placed in a read message production queue.
The server device can read the class which needs to provide the service to the outside, declare the interface of the external service in an annotation form, register the class by a uniform Sign method, and store the class into the memory of the server device in a key-value form, wherein the key is the name of an annotation instance, and the value stores an actual class method and a parameter list. Where annotations may identify that a method may be used for remote invocation, methods that are not annotated may not be remotely invoked.
S400, selecting a thread from the thread pool to execute the message in the message production queue and feeding back an execution result to the client device.
In particular, a java thread pool may be used to manage concurrent connections, asynchronous processing connections, and remote invocation requests.
Wherein, step S400 may include:
acquiring a write message in the write message execution production queue from the write message consumer thread pool, and feeding back an execution result to the client device after the write message is successfully executed, wherein the server device puts the thread back to the write message consumer thread pool after the write message is executed by the thread;
and obtaining the read message in the read message production queue executed by the thread from the read message consumer thread pool, and feeding back an execution result to the client device after the read message is successfully executed, wherein the server device puts the thread back to the read message consumer thread pool after the read message is executed by the thread.
The threads for reading and writing are separated through the independent read message production queue and write message production queue.
Optionally, as shown in fig. 2, another remote procedure call method provided in the embodiment of the present invention may further include:
s500, monitoring the execution result of the thread executing the message in the message production queue;
s600, judging whether the execution result meets a preset trigger condition, and if so, executing the step S700;
and S700, triggering an event matched with the met triggering condition.
Specifically, the invention can adopt a selector model of Java.
Specifically, in other embodiments of the present invention, before the server device listens for the connection request of the client device, the method may further include:
binding a monitoring address TServer socket for monitoring the connection request of the client equipment, and registering an interface method stub RpcProxyprocessor connected with the client equipment;
starting an IO thread, creating a Selector, registering the ServerSocketChannel to the Selector to monitor a connection request of a client device, and polling a ready Selector key by the Selector, wherein the Selector key is an object identifier of an event registered in a channel ServerSocketChannel when the client device is connected with a server device.
Specifically, after the RPC request is parsed, ByteBuffer may be asynchronously written to the ServerSocketChannel.
The ServerSocketChannel is a channel that can monitor a new incoming TCP connection, just like a ServerSocket in a standard IO.
In this case, step S100 may include:
after the connection request of the client device is monitored from the monitoring address TServerSocket, setting a parameter for connecting with the client device sending the connection request by the acceptimipl, and establishing a link with the client device sending the connection request according to the set parameter;
step S300 may include:
determining, by the Selector, a method requested to be called by the client device, executing the method requested to be called by the client device to generate a message corresponding to the method, and placing the generated message in a message production queue, wherein the generated message includes a write message and/or a read message;
the tserver socket is mainly used as a socket manager of the server side. Which encapsulates the socket of the server device. After the socket is opened, the server device is in a monitoring state, after connection requests of other machines are received, a link is established with the client device, a new socket is created for data transmission with the client device, and at the moment, the TServer socket component continues to monitor the connection requests of the client device.
The remote procedure call method provided by the embodiment of the invention can receive a remote procedure call protocol (RPC) request sent by the client equipment; analyzing the RPC request according to a preset RPC protocol to obtain identification information of a method called by the RPC request; determining a method requested to be called by the client equipment, executing the method requested to be called by the client equipment to generate a message corresponding to the method, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message; and selecting a thread from a thread pool to execute the message in the message production queue and feeding back an execution result to the client device. The method can be executed through the identification information of the method requested to be called in the RPC request, so that an IDL file does not need to be generated, and the RPC calling process is simplified. The method calling method and the device do not need to modify the definition of the client device on the method to be called, the client device can call the method only through the identification information of the method, and the method calling method and the device are simple and easy to use.
Corresponding to the method provided by the embodiment of the invention, the embodiment of the invention also provides a remote procedure calling device.
As shown in fig. 3, a remote procedure call apparatus provided in an embodiment of the present invention is applied to a server device, where the server device is in communication connection with a client device, and the apparatus may include: a request receiving unit 100, a request parsing unit 200, a method execution unit 300, and a message execution unit 400;
the request receiving unit 100 is configured to receive a remote procedure call protocol (RPC) request sent by the client device;
the request analysis unit 200 is configured to analyze the RPC request according to a preset RPC protocol to obtain identification information of a method called by the RPC request;
the method executing unit 300 is configured to determine a method requested to be called by the client device, execute the method requested to be called by the client device to generate a message corresponding to the method, and place the generated message in a message production queue, where the generated message includes a write message and/or a read message;
the message execution unit 400 is configured to select a thread from a thread pool to execute the message in the message production queue and feed back an execution result to the client device.
Wherein the apparatus may further comprise: a request listening unit and a link establishment unit,
the request monitoring unit is configured to monitor a connection request of the client device before the request receiving unit 100 receives a remote procedure call protocol (RPC) request sent by the client device;
and the link establishing unit is used for establishing a link with the client equipment after monitoring the connection request of the client equipment.
Specifically, parameters for connecting with the client device may be set by the acceptimipl according to the connection request of the client device to establish a link with the client device.
Further, in order to keep the link with the client device stable, the present invention may further include: a link monitoring unit and a link reconstruction unit,
the link monitoring unit is used for monitoring the link state with the client equipment;
and the link reestablishing unit is used for reestablishing the link with the client device when the link between the server device and the client device is disconnected.
Because the server-side equipment monitors the link state with the client-side equipment, when the link between the server-side equipment and the client-side equipment is disconnected, the link with the client-side equipment can be reestablished in time to complete corresponding work, and the working efficiency is improved.
In other embodiments of the present invention, the server device may periodically scan all links with each client device, and perform corresponding processing according to the number of links. For example: and setting the minimum link quantity and the maximum link quantity, and recycling the links which are not used in the current link when the current link quantity is greater than the maximum link quantity so as to reduce the current link quantity and save the system overhead caused by excessive link quantity.
The method is suitable for both Java.NIO and standard IO, wherein the same TServer is adopted for the Java.NIO and the standard IO, the Java.NIO starts threads with fixed number to process Java.NIO events according to the number of CPU cores of the server device, and the standard IO can set the minimum thread number and the maximum thread number to process the standard IO events according to actual conditions.
The identification information of the method may be: the method signature is requested.
The preset RPC protocol can be as follows:
the format of the RPC request is as follows: packet length, header size, request method signature, message type, sequence number SEQID, extended data length, encoded extended data content, body content length, body data.
Header data in the form of KEY ═ VALUE is stored in the tmessage.name of the header of the RPC request. The packet header comprises a request method signature, a message type, a sequence number SEQID, an extended data length and encoded extended data content; wherein the request method signature consists of the name of the requested method and a list of parameters. SEQID is used for identifying different RPC requests, and the encoded extended data content is used for storing the request and the response content. The message type is a type of remote method call, and includes four types: CALL (service CALL), EXCEPTION (EXCEPTION handling), REPLY (request response), and ONEWAY (extended use). The extension data is mainly used for other data transmission and method calling except service data, and can also be used for method call-back.
Specifically, since the server device may be in communication connection with a plurality of client devices, the server device often needs to process a plurality of concurrent RPC requests, and in this case, the concurrent RPC requests may be processed in the message production queue.
The method execution unit 300 may be specifically configured to: locally searching a key with the obtained identification information in the server-side equipment, generating a message corresponding to the method according to a method parameter stored in a value corresponding to the key, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message;
when the write message is generated, the generated write message is put into a write message production queue;
and when the read message is generated, the generated read message is placed in a read message production queue.
The server device can read the class which needs to provide the service to the outside, declare the interface of the external service in an annotation form, register the class by a uniform Sign method, and store the class into the memory of the server device in a key-value form, wherein the key is the name of an annotation instance, and the value stores an actual class method and a parameter list. Where annotations may identify that a method may be used for remote invocation, methods that are not annotated may not be remotely invoked.
In particular, a java thread pool may be used to manage concurrent connections, asynchronous processing connections, and remote invocation requests.
The message execution unit 400 may include: a write message handling sub-unit and a read message handling sub-unit,
the write message processing subunit is configured to acquire, from the write message consumer thread pool, a write message in the write message production queue executed by a thread, and feed back an execution result to the client device after the write message is successfully executed, where after the write message is executed by the thread, the server device returns the thread to the write message consumer thread pool;
the read message processing subunit is configured to acquire a read message in the read message production queue executed by a thread from the read message consumer thread pool, and feed back an execution result to the client device after the read message is successfully executed, where the server device puts the thread back to the read message consumer thread pool after the read message is executed by the thread.
The threads for reading and writing are separated through the independent read message production queue and write message production queue.
Optionally, as shown in fig. 4, another remote procedure call apparatus provided in the embodiment of the present invention may further include: a result monitoring unit 500, a trigger judging unit 600 and an event triggering unit 700,
the result monitoring unit 500 is configured to monitor an execution result of executing the message in the message production queue by a thread;
the trigger determining unit 600 is configured to determine whether the execution result meets a preset trigger condition, and if so, trigger the event triggering unit 700;
the event trigger unit 700 is configured to trigger an event matching the satisfied trigger condition.
Specifically, the invention can adopt a selector model of Java.
Specifically, in other embodiments of the present invention, the apparatus may further include: an address binding unit and a selector creating unit,
the address binding unit is configured to bind a monitoring address tserver socket for monitoring the connection request of the client device before the request monitoring unit monitors the connection request of the client device, and register an interface method stub RpcProxyProcessor for connecting with the client device;
the Selector creating unit is used for starting an IO thread, creating a Selector, registering a ServerSocketChannel to the Selector to monitor a connection request of the client device, and polling a ready Selector key by the Selector, wherein the Selector key is an object identifier of an event registered in a channel ServerSocketChannel when the client device is connected with the server device.
Specifically, after the RPC request is parsed, ByteBuffer may be asynchronously written to the ServerSocketChannel.
The ServerSocketChannel is a channel that can monitor a new incoming TCP connection, just like a ServerSocket in a standard IO.
In this case, the request receiving unit 100 may be specifically configured to, after monitoring the connection request of the client device from the monitoring address TServerSocket, set, by the acceptimipl, a parameter for connecting with the client device that sends the connection request, and establish a link with the client device that sends the connection request according to the set parameter;
the method executing unit 300 may be specifically configured to determine, by the Selector, a method requested to be called by the client device, execute the method requested to be called by the client device to generate a message corresponding to the method, and place the generated message in a message production queue, where the generated message includes a write message and/or a read message;
the tserver socket is mainly used as a socket manager of the server side. Which encapsulates the socket of the server device. After the socket is opened, the server device is in a monitoring state, after connection requests of other machines are received, a link is established with the client device, a new socket is created for data transmission with the client device, and at the moment, the TServer socket component continues to monitor the connection requests of the client device.
The remote procedure call device provided by the embodiment of the invention can receive a remote procedure call protocol (RPC) request sent by the client equipment; analyzing the RPC request according to a preset RPC protocol to obtain identification information of a method called by the RPC request; determining a method requested to be called by the client equipment, executing the method requested to be called by the client equipment to generate a message corresponding to the method, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message; and selecting a thread from a thread pool to execute the message in the message production queue and feeding back an execution result to the client device. The method can be executed through the identification information of the method requested to be called in the RPC request, so that an IDL file does not need to be generated, and the RPC calling process is simplified. The method calling method and the device do not need to modify the definition of the client device on the method to be called, the client device can call the method only through the identification information of the method, and the method calling method and the device are simple and easy to use.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (8)

1. A remote procedure call method is applied to a server device, the server device is in communication connection with a client device, wherein the server device can read classes requiring external services, interfaces of the external services are declared in an annotation form, a unified Sign method is used for registration, the classes are stored in a server device memory in a key-value form, the key is an annotation instance name, a value stores an actual class method and a parameter list, and when a service call request is received, a specified service is identified from the key and call is realized, and the method comprises the following steps:
receiving a remote procedure call protocol (RPC) request sent by the client equipment;
analyzing the RPC request according to a preset RPC protocol to obtain identification information of a method called by the RPC request;
determining a method requested to be called by the client equipment, executing the method requested to be called by the client equipment to generate a message corresponding to the method, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message;
selecting a thread from a thread pool to execute the message in the message production queue and feeding back an execution result to the client device;
wherein, the preset RPC protocol is as follows:
the format of the RPC request is as follows: packet length, header size, request method signature, message type, sequence number SEQID, extended data length, encoded extended data content, body content length, body data; the packet header of the RPC request comprises: the request method signature, the message type, the sequence number SEQID, the extended data length and the encoded extended data content; the request method signature is composed of a name and parameter list of the requested method; the SEQID is used for identifying different RPC requests; the encoded extended data content is used for storing request and response content; the message type is a type of remote method call, and includes four types: service invocation, exception handling, request response and extended use.
2. The method of claim 1, further comprising:
monitoring the execution result of the thread executing the message in the message production queue;
and judging whether the execution result meets a preset trigger condition, if so, triggering an event matched with the met trigger condition.
3. The method according to claim 1 or 2, wherein before the receiving of the remote procedure call protocol (RPC) request sent by the client device, the method further comprises:
the server side equipment monitors a connection request of the client side equipment;
and after monitoring the connection request of the client equipment, establishing a link with the client equipment.
4. The method of claim 3, further comprising:
the server side equipment monitors the link state with the client side equipment;
and when the link between the server side equipment and the client side equipment is disconnected, the link with the client side equipment is reestablished.
5. The method of claim 1, wherein determining the method requested to be called by the client device, executing the method requested to be called by the client device to generate a message corresponding to the method, and placing the generated message in a message production queue comprises:
locally searching a key with the obtained identification information in the server-side equipment, generating a message corresponding to the method according to a method parameter stored in a value corresponding to the key, and putting the generated message into a message production queue;
when the write message is generated, the generated write message is put into a write message production queue;
and when the read message is generated, the generated read message is placed in a read message production queue.
6. The method of claim 5, wherein selecting a thread from a thread pool to execute a message in the message production queue and feeding back an execution result to the client device comprises:
acquiring a write message in the write message execution production queue from the write message consumer thread pool, and feeding back an execution result to the client device after the write message is successfully executed, wherein the server device puts the thread back to the write message consumer thread pool after the write message is executed by the thread;
and obtaining the read message in the read message production queue executed by the thread from the read message consumer thread pool, and feeding back an execution result to the client device after the read message is successfully executed, wherein the server device puts the thread back to the read message consumer thread pool after the read message is executed by the thread.
7. The method of claim 3, wherein before the server device listens for the connection request of the client device, the method further comprises:
binding a monitoring address TServer socket for monitoring the connection request of the client equipment, and registering an interface method stub RpcProxyprocessor connected with the client equipment;
starting an IO thread, creating a Selector, registering a channel ServerSocketChannel to the Selector to monitor a connection request of client equipment, and polling a ready Selector key by the Selector, wherein the Selector key is an object identifier of an event registered in the channel ServerSocketChannel when the client equipment is connected with the server equipment;
after monitoring the connection request of the client device, establishing a link with the client device includes:
after the connection request of the client device is monitored from the monitoring address TServerSocket, setting a parameter for connecting with the client device sending the connection request by the acceptimipl, and establishing a link with the client device sending the connection request according to the set parameter;
the determining the method called by the client device request, executing the method called by the client device request to generate a message corresponding to the method, and putting the generated message into a message production queue, includes:
and the Selector determines the method requested to be called by the client equipment, executes the method requested to be called by the client equipment to generate a message corresponding to the method, and places the generated message into a message production queue.
8. A remote procedure call device is applied to a server device, the server device is in communication connection with a client device, wherein the server device can read classes requiring external services, an interface of the external services is declared in an annotation form, a unified Sign method is used for registration, the classes are stored in a memory of the server device in a key-value form, the key is an annotation instance name, a value stores an actual class method and a parameter list, and when a service call request is received, a specified service is identified from the key and call is realized, and the device comprises: the device comprises a request receiving unit, a request analyzing unit, a method executing unit and a message executing unit;
the request receiving unit is used for receiving a remote procedure call protocol (RPC) request sent by the client equipment;
the request analysis unit is used for analyzing the RPC request according to a preset RPC protocol to obtain identification information of a method called by the request in the RPC request;
the method execution unit is used for determining a method requested to be called by the client device, executing the method requested to be called by the client device to generate a message corresponding to the method, and putting the generated message into a message production queue, wherein the generated message comprises a write message and/or a read message;
the message execution unit is used for selecting a thread from a thread pool to execute the message in the message production queue and feeding back an execution result to the client device;
wherein, the preset RPC protocol is as follows:
the format of the RPC request is as follows: packet length, header size, request method signature, message type, sequence number SEQID, extended data length, encoded extended data content, body content length, body data; the packet header of the RPC request comprises: the request method signature, the message type, the sequence number SEQID, the extended data length and the encoded extended data content; the request method signature is composed of a name and parameter list of the requested method; the SEQID is used for identifying different RPC requests; the encoded extended data content is used for storing request and response content; the message type is a type of remote method call, and includes four types: service invocation, exception handling, request response and extended use.
CN201710146522.6A 2017-03-13 2017-03-13 Remote procedure calling method and device Active CN106648940B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710146522.6A CN106648940B (en) 2017-03-13 2017-03-13 Remote procedure calling method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710146522.6A CN106648940B (en) 2017-03-13 2017-03-13 Remote procedure calling method and device

Publications (2)

Publication Number Publication Date
CN106648940A CN106648940A (en) 2017-05-10
CN106648940B true CN106648940B (en) 2020-05-22

Family

ID=58847370

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710146522.6A Active CN106648940B (en) 2017-03-13 2017-03-13 Remote procedure calling method and device

Country Status (1)

Country Link
CN (1) CN106648940B (en)

Families Citing this family (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107277029B (en) * 2017-06-30 2020-01-03 武汉斗鱼网络科技有限公司 Remote procedure call method and device and computer equipment
CN109214741B (en) * 2017-07-07 2021-11-12 北京京东尚科信息技术有限公司 Early warning method and early warning system for monitoring indexes
CN109660573B (en) * 2017-10-10 2021-10-15 北京京东尚科信息技术有限公司 Data transmission method and device
CN108614776B (en) * 2018-05-04 2021-08-31 艺龙网信息技术(北京)有限公司 Dynamic construction method and system for cross-language protocol test request
CN108776623B (en) * 2018-06-08 2020-09-08 武汉斗鱼网络科技有限公司 Optimization method, computer equipment and storage medium
CN108958951B (en) * 2018-06-08 2021-05-28 武汉斗鱼网络科技有限公司 Optimization method, computer equipment and storage medium
CN108965312A (en) * 2018-07-30 2018-12-07 深圳高新兴物联科技有限公司 Remote invocation method, device, system and storage medium
CN109753370A (en) * 2018-12-28 2019-05-14 北京东方国信科技股份有限公司 A kind of low time delay, the high remote procedure calling (PRC) method handled up
CN109981674B (en) * 2019-04-04 2021-08-17 北京信而泰科技股份有限公司 Remote procedure calling method, device, equipment and medium
CN110457144B (en) * 2019-08-05 2021-12-07 北京字节跳动网络技术有限公司 Method, device, medium and equipment for realizing front-end application
CN111405029B (en) * 2020-03-12 2023-06-02 北京字节跳动网络技术有限公司 Request processing method and device
CN111913819A (en) * 2020-08-07 2020-11-10 上海格尔安全科技有限公司 RPC-based USBKEY access method
CN112256567A (en) * 2020-09-29 2021-01-22 航天科工广信智能技术有限公司 Remote calling simulation and test system
CN112433870A (en) * 2020-12-01 2021-03-02 网易(杭州)网络有限公司 Data calling method and device, computer readable storage medium and electronic equipment
CN112698970A (en) * 2020-12-31 2021-04-23 北京千方科技股份有限公司 Service calling method and device for micro-service architecture and computer storage medium
CN113778786B (en) * 2021-08-09 2023-11-14 珠海金智维信息科技有限公司 Monitoring middleware
CN113852635B (en) * 2021-09-26 2024-05-28 招商银行股份有限公司 Task processing method, device, terminal equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103116520A (en) * 2012-11-02 2013-05-22 深圳键桥通讯技术股份有限公司 Remote procedure call remote position control (RPC) method based on transmission control protocol (TCP)/user datagram protocol (UDP)
CN104270470A (en) * 2014-10-24 2015-01-07 杭州高达软件系统股份有限公司 Remote service invocation method, device and system
CN106020963A (en) * 2016-06-07 2016-10-12 中国建设银行股份有限公司 Cross-system internal service calling method and device
CN106161537A (en) * 2015-04-10 2016-11-23 阿里巴巴集团控股有限公司 The processing method of remote procedure call, device, system and electronic equipment
CN106357713A (en) * 2015-07-16 2017-01-25 北京京东尚科信息技术有限公司 Remote procedure call realizing method, client side device and server device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103116520A (en) * 2012-11-02 2013-05-22 深圳键桥通讯技术股份有限公司 Remote procedure call remote position control (RPC) method based on transmission control protocol (TCP)/user datagram protocol (UDP)
CN104270470A (en) * 2014-10-24 2015-01-07 杭州高达软件系统股份有限公司 Remote service invocation method, device and system
CN106161537A (en) * 2015-04-10 2016-11-23 阿里巴巴集团控股有限公司 The processing method of remote procedure call, device, system and electronic equipment
CN106357713A (en) * 2015-07-16 2017-01-25 北京京东尚科信息技术有限公司 Remote procedure call realizing method, client side device and server device
CN106020963A (en) * 2016-06-07 2016-10-12 中国建设银行股份有限公司 Cross-system internal service calling method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
云计算中可扩展的远程服务调用机制的设计与实现;李洋;《中国优秀硕士学位论文全文数据库 信息科技辑》;20140415(第4期);I139-107 *

Also Published As

Publication number Publication date
CN106648940A (en) 2017-05-10

Similar Documents

Publication Publication Date Title
CN106648940B (en) Remote procedure calling method and device
CN110300050B (en) Message pushing method and device, computer equipment and storage medium
CN111258627B (en) Interface document generation method and device
CN101388887A (en) Network service processing method and system
CN111447170B (en) Data processing method and system, computer system and computer readable medium
CN112054998A (en) Proxy service method, device, equipment and computer readable storage medium
CN113835911B (en) Intranet penetration agent method, system, host and computer readable storage medium
CN112486707A (en) Redis-based message asynchronous consumption method and device
CN115102857A (en) Method, device, equipment and storage medium for updating client configuration data
CN113342503B (en) Real-time progress feedback method, device, equipment and storage medium
CN115622906A (en) Application log capturing system and method
CN114741261A (en) Distributed link tracking method, device, equipment and storage medium
EP2445171A1 (en) File transfer protocol client and implementing method thereof
CN113965628A (en) Message scheduling method, server and storage medium
CN111352715A (en) Method, system, terminal and storage medium for destroying flash thread
CN110557428B (en) Script interpretation type service agent method and system based on Kubernetes
CN113743630A (en) Method and device for executing intelligent call reservation
CN108668306B (en) Data acquisition system with built-in mobile operating system
CN106959887B (en) Business process cooperation system and method of distributed program
US20020083209A1 (en) Method and system for registering binary data
CN112671822B (en) Service request processing method, device, storage medium, server and system
CN115766278B (en) Firewall policy generation method, device, equipment and storage medium
CN115378792B (en) Alarm processing method, device and storage medium
CN113608900B (en) Method, device, equipment and medium for calling algorithm model
CN115051866B (en) Message processing method and device, storage medium and electronic equipment

Legal Events

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