Skip to content

Latest commit

 

History

History
82 lines (70 loc) · 3.33 KB

rpc.md

File metadata and controls

82 lines (70 loc) · 3.33 KB

RPC is a core component, and micro services built inside PSLX (for example instant messaging and email) are concrete implementations of RPC. To build an RPC service using PSLX, one first needs to take a look at the abstract class implementation defined in rpc_base. The following functions are provided

__init__(service_name, rpc_storage)
  • Description: Create an RPC instance with given name and underlying storage.
  • Arguments:
    1. service_name: the name of the rpc service. Needs to be unique.
    2. rpc_storage: the partitioner storage for storing the GenericRPCRequestResponsePair. If None, the GenericRPCRequestResponsePair won't be stored.

!!! info Function needs to be implemented by specific application.

get_response_and_status_impl(request)
  • Description: get corresponding response and status from the request.
  • Arguments:
    1. request: a proto message containing user defined request information.
  • Explanation:
    1. The request and response can be any proto message type user defines.
    2. A concrete implementation of RPCBase needs to specify the type of request by setting REQUEST_MESSAGE_TYPE as a class level variable.

In addition to inheriting and implementing a RPC class, one also needs to create a client class inheriting client_base. The client_base.py provides the following functions

__init__(client_name, server_url)
  • Description: Create an client instance.
  • Arguments:
    1. client_name: the name of the rpc client.
    2. server_url: the url to the rpc server.
send_request(request)
  • Description: Send request to the server and get response.
  • Arguments:
    1. request: the request proto message.

The user of PSLX can also define other function to create a specific request and call send_request inside the function. One example can be found at instant_messaging/client.py. In this example, a customized function send_message wraps the send_request and then allows user to pass more concrete arguments to interact with rpc server.

Inside PSLX, RPC requests and responses will finally be parsed as Any proto message and hence the interface is universal. To create a PSLX server, the user of PSLX needs to bind an RPC to a server using the methods provided by generic_server.

_init__(server_name)
  • Description: Create an generic server instance.
  • Arguments:
    1. server_name: the name of the server. Needs to be unique.
create_server(max_worker, server_url)
  • Description: Create an generic server.
  • Arguments:
    1. max_worker: the maximum number of workers for the server.
    2. server_url: the url to the rpc server.

!!! note Each generic server is only allowed to bind to one rpc instance.

bind_rpc(rpc)
  • Description: Bind an RPC instance to the server.
  • Arguments:
    1. rpc: the rpc instance to be binded.
start_server()
  • Description: Start running the server.