Expand description
Unary call helper: deadline, one re-auth retry for reads.
Internal plumbing of the connectors, public so that tests and tools can use it. Application code
calls the broker through the connector traits or FinamRaw.
§Examples
The difference between a read and a command, with a call that always answers UNAUTHENTICATED
the first time:
use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};
use std::time::Duration;
use brokapi_finam::rpc::unary;
use brokapi_finam_protocol::{ApiEndpoint, start_token_manager};
let tokens = start_token_manager(&endpoint, SECRET, "").await?;
let calls = Arc::new(AtomicU32::new(0));
let call = || {
let calls = Arc::clone(&calls);
async move {
match calls.fetch_add(1, Ordering::SeqCst) {
0 => Err(tonic::Status::unauthenticated("token expired")),
_ => Ok(tonic::Response::new("ok")),
}
}
};
// A read renews the token and repeats once.
let value = unary(&tokens, Duration::from_secs(5), true, call).await?;
assert_eq!(value, "ok");
assert_eq!(calls.load(Ordering::SeqCst), 2);
assert_eq!(tokens.generation(), 2);
// A command is sent once, whatever the answer.
calls.store(0, Ordering::SeqCst);
let err = unary(&tokens, Duration::from_secs(5), false, call).await.unwrap_err();
assert!(err.is_unauthenticated());
assert_eq!(calls.load(Ordering::SeqCst), 1);Structs§
- Rpc
- Everything a connector needs to make calls: clients, quota, deadline.
Functions§
- unary
- Runs
fwith a deadline. OnUNAUTHENTICATEDandretry_unauthrenews the JWT and calls once more. Never setretry_unauthfor commands (no automatic retry of trading commands).