-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmy_virtual_object.rs
39 lines (35 loc) · 1022 Bytes
/
my_virtual_object.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use restate_sdk::prelude::*;
#[restate_sdk::object]
pub trait MyVirtualObject {
async fn my_handler(name: String) -> Result<String, HandlerError>;
#[shared]
async fn my_concurrent_handler(name: String) -> Result<String, HandlerError>;
}
pub struct MyVirtualObjectImpl;
impl MyVirtualObject for MyVirtualObjectImpl {
async fn my_handler(
&self,
ctx: ObjectContext<'_>,
greeting: String,
) -> Result<String, HandlerError> {
Ok(format!("Greetings {} {}", greeting, ctx.key()))
}
async fn my_concurrent_handler(
&self,
ctx: SharedObjectContext<'_>,
greeting: String,
) -> Result<String, HandlerError> {
Ok(format!("Greetings {} {}", greeting, ctx.key()))
}
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
HttpServer::new(
Endpoint::builder()
.bind(MyVirtualObjectImpl.serve())
.build(),
)
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
.await;
}