Configuration
KrpcConfig
is a class used to configure KrpcClient
and KrpcServer
(not to be confused with RpcClient
and RpcServer
).
It has two children: KrpcConfig.Client
and KrpcConfig.Server
. Client
and Server
may have shared properties as well as distinct ones. To create instances of these configurations, DSL builders are provided:
rpcClientConfig
rpcServerConfig
The following configuration options are available:
serialization
DSL
This parameter defines how serialization should work in RPC services and is present in both client and server configurations.
The serialization process is used to encode and decode data in RPC requests, so that the data can be transferred through the network.
Currently only StringFormat
and BinaryFormat
from kotlinx.serialization are supported, and by default you can choose from Json, Protobuf or Cbor formats:
Only last defined format will be used to serialize requests. If no format is specified, a runtime error will be thrown. You can also define a custom format.
connector
DSL
Connector is a part of kRPC that is responsible for sending and receiving data over the network. You can configure the following parameters:
waitTimeout
- timeout for waiting for a service to be registered. Sometimes services can be registered after the server starts, and after the first requests starts to arrive from a peer. This parameter defines how long the server will wait for a service to be registered.The default value is
Duration.INFINITE
.Also, available a value of
dontWait()
.callTimeout
- timeout for processing one message.The default value is
Duration.INFINITE
.perCallBufferSize
- size of the messages buffer for one call. The buffer ignores the size in bytes and only counts the number of messages. This effectively provides a backpressure mechanism. If a peer is slow to process the message during a call, the buffer will be filled up and the sender will wait before sending more messages.Note that this is per call, not per connection.
The default value is
1000
.
Example: