Basically Connection read host_port each recoonection moment. Trait gives ability to update host_port in realtime without restarting the application.
pub struct MyNoSqlTcpReaderSettings {}
#[async_trait::async_trait]
impl my_no_sql_tcp_reader::MyNoSqlTcpConnectionSettings for MyNoSqlTcpReaderSettings {
async fn get_host_port(&self) -> String {
"localhost:5125".to_string()
}
}
The Serde and https://github.com/MyJetTools/my-no-sql-macros macros libraries are used.
Without expiration
#[my_no_sql_macros::my_no_sql_entity("test")]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TestEntity {
}
With expiration
#[my_no_sql_macros::my_no_sql_entity("test")]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TestEntity {
#[serde(rename = "Expires")]
expires: String,
}
let connection = my_no_sql_tcp_reader::MyNoSqlTcpConnection::new(
"app_name".to_string(),
Arc::new(MyNoSqlTcpReaderSettings {}),
);
let reader: Arc<MyNoSqlDataReader<TestEntity>> = connection.get_reader().await;
connection.start(my_logger::LOGGER.clone()).await;
let entity = reader.get_entity("partition_key", "row_key").await;
println!("{:?}", entity);
let entity = reader
.get_entity_with_callback_to_server("partition_key", "row_key")
.set_row_last_read_moment()
.set_partition_last_read_moment()
.set_row_expiration_moment(Some(now))
.execute()
.await;
println!("{:?}", entity);