RpcSendService

class RpcSendService(loggerFactory: Logger.Factory, protoBuf: ProtoBuf, session: RpcWebSocketSession)

Service class responsible for handling RPC (Remote Procedure Call) communication over a WebSocket session.

This class provides methods for sending various types of requests and handling the responses in a clustered system. The communication is conducted via serialization and deserialization of messages using Kotlin serialization with ProtoBuf format.

Parameters

loggerFactory

Factory for creating logger instances for this service to enable structured logging during communication and debugging.

protoBuf

The ProtoBuf serializer used for encoding and decoding messages.

session

The WebSocket session over which the RPC requests and responses are transmitted.

This class includes support for the following operations:

  • Sending an echo message.

  • Sending fire-and-forget messages (tell).

  • Sending requests with expected responses (ask).

  • Querying the status and statistics of a remote actor.

  • Initiating the shutdown of a remote actor.

  • Closing the WebSocket session when communication is complete.

The service ensures reliability and data consistency by validating response IDs with the request IDs during each interaction. Any inconsistency raises an error, ensuring the integrity of the communication process.

Additional functionality is provided via a companion object:

  • Managing a shared RPC message dispatcher that associates responses to their corresponding requests.

  • Ensuring unique message IDs for requests by maintaining an internal counter with safe concurrent access.

  • Handling incoming responses sent from the remote side by deserializing and forwarding them to the RPC manager.

Constructors

Link copied to clipboard
constructor(loggerFactory: Logger.Factory, protoBuf: ProtoBuf, session: RpcWebSocketSession)

Creates an instance of RpcSendService with the specified logger factory, serialization mechanism (ProtoBuf), and WebSocket session.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Sends a message to a specified actor address and waits for a response, ensuring the response corresponds to the sent request.

Link copied to clipboard
suspend fun close()

Closes the current session associated with the RpcSendService.

Link copied to clipboard

Sends an echo request with a given message and awaits a response.

Link copied to clipboard

Sends a shutdown request to the specified actor address and waits for the response.

Link copied to clipboard

Sends a stats request to the specified actor address and waits for the corresponding response.

Link copied to clipboard

Sends a status request to the specified actor address and awaits the corresponding response.

Link copied to clipboard

Sends a message to a specified actor address and waits for a response.