Distributed stateful services inspired by Orleans
This crate provides a framework for scalable, distributed and stateful services based on message passing between objects
Application
Most of your application code will be written in forms of ServiceObjects and Messages
use async_trait;
use *;
use ;
use Arc;
Running Server
To run your application you need to spin up your servers, the Server
TODO: Include example of other databases
use *;
use ;
use SqlObjectPlacementProvider;
# // Copied from the snippet above
# use async_trait;
# use ;
# use Arc;
#
#
#
#
#
#
#
#
async
Client
Communicating with the cluster is just a matter of sending the serialized known messages via TCP.
The [client] module provides an easy way of achieving this:
use rio_rs::prelude::*;
use rio_rs::cluster::storage::sql::{SqlMembersStorage};
# // Copied from the snippet above
# use async_trait::async_trait;
# use serde::{Deserialize, Serialize};
# use std::sync::Arc;
# #[derive(TypeName, Message, Deserialize, Serialize)]
# pub struct HelloMessage {
# pub name: String
# }
# #[derive(TypeName, Message, Deserialize, Serialize)]
# pub struct HelloResponse {}
# #[derive(TypeName, WithId, Default)]
# pub struct HelloWorldService {
# pub id: String,
# }
# #[async_trait]
# impl Handler<HelloMessage> for HelloWorldService {
# type Returns = HelloResponse;
# type Error = NoopError;
# async fn handle(
# &mut self,
# message: HelloMessage,
# app_data: Arc<AppData>,
# ) -> Result<Self::Returns, Self::Error> {
# println!("Hello world");
# Ok(HelloResponse {})
# }
# }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Member storage configuration (Rendezvous)
let pool = SqlMembersStorage::pool()
.connect("sqlite::memory:")
.await?;
let members_storage = SqlMembersStorage::new(pool);
# members_storage.prepare().await;
// Create the client
let mut client = ClientBuilder::new()
.members_storage(members_storage)
.build()?;
let payload = HelloMessage { name: "Client".to_string() };
let response: HelloResponse = client
.send::<HelloResponse, NoopError>(
"HelloWorldService".to_string(),
"any-string-id".to_string(),
&payload,
).await?;
// response is a `HelloResponse {}`
Ok(())
}