23
23
In this case, you can use the generated code.
24
24
</tip >
25
25
<p >
26
- To be able to obtain an instance of your service, you need to have an <code >RPCClient </code >.
26
+ To be able to obtain an instance of your service, you need to have an <code >RpcClient </code >.
27
27
You can call the <code >withService()</code > method on your client:
28
28
</p >
29
29
<code-block lang =" kotlin" >
30
- val rpcClient: RPCClient
30
+ val rpcClient: RpcClient
31
31
32
32
val myService: MyService = rpcClient.withService< MyService> ()
33
33
</code-block >
34
34
<p >
35
35
Now you have your client instance that is able to send RPC requests to your server.
36
- <code >RPCClient </code > can have multiple services that communicate through it.
37
- Conceptually, <code >RPCClient </code > is an abstraction of a client,
36
+ <code >RpcClient </code > can have multiple services that communicate through it.
37
+ Conceptually, <code >RpcClient </code > is an abstraction of a client,
38
38
that is able to convent service requests
39
- (represented by < code >RPCCall</ code > and <code >RPCField </code > classes )
39
+ (represented by the <code >RpcCall </code > class )
40
40
into actual network requests.
41
41
</p >
42
42
<p >
43
- You can provide your own implementations of the <code >RPCClient </code >.
43
+ You can provide your own implementations of the <code >RpcClient </code >.
44
44
But <code >kotlinx.rpc</code > already provides one out-of-the-box solution that uses
45
45
in-house RPC protocol (called kRPC), and we are working on supporting more protocols
46
46
(with priority on gRPC).
47
47
</p >
48
48
49
- <chapter title =" KRPCClient — RPCClient for kRPC Protocol" id =" krpcclient-rpcclient-for-krpc-protocol" >
50
- <p ><code >KRPCClient </code > is an abstract class that implements <code >RPCClient </code > and kRPC protocol
49
+ <chapter title =" KrpcClient — RpcClient for kRPC Protocol" id =" krpcclient-rpcclient-for-krpc-protocol" >
50
+ <p ><code >KrpcClient </code > is an abstract class that implements <code >RpcClient </code > and kRPC protocol
51
51
logic.
52
52
The only thing required to be implemented is the transporting of the raw data.
53
- Abstract transport is represented by <code >RPCTransport </code > interface.</p >
54
- <p >To implement your own <code >RPCTransport </code >
53
+ Abstract transport is represented by <code >KrpcTransport </code > interface.</p >
54
+ <p >To implement your own <code >KrpcTransport </code >
55
55
you need to be able to transfer strings and/or raw bytes (Kotlin's <code >ByteArray</code >).
56
56
Additionally, the library will provide you with <a href =" transport.topic" >integrations with different
57
57
libraries</a > that are used to work with the network.
58
58
</p >
59
59
<p >See below an example usage of kRPC with a custom transport:</p >
60
60
61
61
<code-block lang =" kotlin" >
62
- class MySimpleRPCTransport : RPCTransport {
63
- val outChannel = Channel< RPCTransportMessage > ()
64
- val inChannel = Channel< RPCTransportMessage > ()
62
+ class MySimpleRpcTransport : KrpcTransport {
63
+ val outChannel = Channel< KrpcTransportMessage > ()
64
+ val inChannel = Channel< KrpcTransportMessage > ()
65
65
66
66
override val coroutineContext: CoroutineContext = Job()
67
67
68
- override suspend fun send(message: RPCTransportMessage ) {
68
+ override suspend fun send(message: KrpcTransportMessage ) {
69
69
outChannel.send(message)
70
70
}
71
71
72
- override suspend fun receive(): RPCTransportMessage {
72
+ override suspend fun receive(): KrpcTransportMessage {
73
73
return inChannel.receive()
74
74
}
75
75
}
76
76
77
- class MySimpleRPCClient : KRPCClient (rpcClientConfig(), MySimpleRPCTransport ())
77
+ class MySimpleRpcClient : KrpcClient (rpcClientConfig(), MySimpleRpcTransport ())
78
78
79
- val client = MySimpleRPCClient ()
79
+ val client = MySimpleRpcClient ()
80
80
val service: MyService = client.withService< MyService> ()
81
81
</code-block >
82
82
</chapter >
83
- </topic >
83
+ </topic >
0 commit comments