rpc_server
« Previous section Next section »
UCloud Developer Guide / Developing UCloud / Micro Library Reference / RPC / RPC Server
RPC Server
The RpcServer
is the object responsible for implementing the server-side of remote procedure calls. The server, like the client, is implemented using plugin based approach. The RpcServer
instance is available from micro.server
and is configured by the ServerFeature
. Inside an RpcServer
we find the following properties:
Property | Description |
---|---|
| The request interceptor is responsible for reading and parsing a network call into an RPC + request. It also responsible for sending the response over the network. |
| The call filters act as middle-ware. The middle-ware can implement features such as: logging and service discovery |
Controllers
An RpcServer
is configured by implementing a Controller
and passing it to configureControllers
in Server.kt
.
Code: Implementing a call is done in a Controller
by calling the implement
function with an associated call handler.
RpcServer.implement
RpcServer.implement
The implement
function attaches a call handler to an associated CallDescription
. You can control in which backends the call handler can run by setting the requiredContext
, by-default the call will be able to handle any context.
The RpcServer
will call the handler
every time a request arrives. The CallHandler
will provide a response by calling either ok(SuccessType)
or error(ErrorType)
.
CallHandler<RequestType, SuccessType, ErrorType>
CallHandler<RequestType, SuccessType, ErrorType>
Properties
Properties | Description |
---|---|
| Contains additional information about the request, such as, reference to the calling user |
| Contains the parsed request |
| Contains a reference to the RPC description |
Member functions
Signifies to the RpcServer
that this call should produce a successful response containing result
. It is an error to call this function twice in a single CallHandler
invocation.
Signifies to the RpcServer
that this call has been handled by interacting directly with the backend (see CallHandler.withContext
). This function must be called if you produce a response directly. This is required for middle-ware to know that the lack of a response object is not a programmer error.
Signifies to the RpcServer
that this call should produce an error response containing result
. It is an error to call this function twice in a single CallHandler
invocation.
Allows a CallHandler
to interact directly with the RPC server backend. We generally recommend that you do not use this function to speak directly to the backend server.
Example:
IngoingCall
IngoingCall
Properties
Returns information about the authenticated security principal. If there is no guarantee that the user is authenticated (see here) then you should use the OrNull
variant.
Returns the raw bearer token used in authenticating the user.
Allows the CallHandler
to modify the data used in auditing.
Returns information about the calling users IP address.
Returns information about the job ID and caused-by IDs.
Returns information about the calling client's user agent.
Returns information about the calling user's active project.
Last updated