Crate relay_system

Source
Expand description

Foundational system components for Relay’s services.

Relay’s system is based on [tokio]. To use any of these components, ensure a tokio runtime is available.

§Services

The basic building block in Relay are asynchronous Services. Each service implements an Interface, which consists of one or many messages that can be sent to the service using its Addr. See the docs of these types for more information on how to implement and use them.

§Shutdown

The static Controller service can listen for process signals and initiate a graceful shutdown. Note that services must check a ShutdownHandle to receive these signals. See the struct level documentation for more information.

Macros§

spawn
Spawns an instrumented task with an automatically generated TaskId.

Structs§

Addr
The address of a Service.
AsyncResponse
Message response resulting in an asynchronous Request.
BroadcastChannel
A channel that broadcasts values to attached senders.
BroadcastRequest
The request when sending an asynchronous message to a service.
BroadcastResponse
Variation of AsyncResponse that efficiently broadcasts responses to many requests.
BroadcastSender
Sends a message response from a service back to the waiting BroadcastRequest.
Builder
Configures a Relay Runtime.
Controller
Service to start and gracefully stop the system runtime.
Handle
Handle to the Runtime.
MonitoredFuture
A future that tracks metrics.
NoResponse
Message response for fire-and-forget messages with no output.
RawMetrics
The raw metrics extracted from a MonitoredFuture.
Receiver
Inbound channel for messages sent through an Addr.
Recipient
An address to a Service implementing any interface that takes a given message.
Request
The request when sending an asynchronous message to a service.
Runtime
A Relay async runtime.
RuntimeMetrics
Handle to the Runtime’s metrics.
SendError
An error when sending a message to a service fails.
Sender
Sends a message response from a service back to the waiting Request.
ServiceError
The service failed.
ServiceId
A per runtime unique identifier for a started service.
ServiceJoinHandle
An owned handle to await the termination of a service.
ServiceMetrics
Collected metrics of a single service.
ServiceObj
Type erased Service.
ServiceSet
Spawns and keeps track of running services.
ServiceStatusError
A ServiceError without the service error/panic.
ServiceStatusJoinHandle
A companion handle to ServiceJoinHandle.
ServicesMetrics
A point in time snapshot of all started services and their ServiceMetrics.
Shutdown
Shutdown request message sent by the Controller to subscribed services.
ShutdownHandle
Notifies a service about an upcoming shutdown.
TaskId
An identifier for tasks spawned by spawn(), used to log metrics.
TokioServiceSpawn
A ServiceSpawn implementation which spawns a service on the current Tokio runtime.

Enums§

ShutdownMode
Determines how to shut down the Relay system.

Traits§

FromMessage
Declares a message as part of an Interface.
Interface
A message interface for services.
MessageResponse
Response behavior of an Interface message.
Service
An asynchronous unit responding to messages.
ServiceSpawn
The ServiceSpawn trait allows for starting a Service on an executor that will run them to completion.
ServiceSpawnExt
Extension trait for ServiceSpawn, providing more convenient methods to spawn a service.

Functions§

channel
Creates an unbounded channel for communicating with a Service.
spawn
Spawns a new asynchronous task, returning a [JoinHandle] for it.
spawn_in
Spawns a new asynchronous task in a specific runtime, returning a [JoinHandle] for it.