Struct pravega_client::event::TransactionalEventWriter
source · pub struct TransactionalEventWriter { /* private fields */ }
Expand description
Write events to a stream transactionally.
Events that are written to the transaction can be committed atomically, which means that reader cannot see any writes prior to committing and will not see any writes if the transaction is aborted.
§Example
use tokio;
use pravega_client_shared::{Timestamp, ScopedStream, Scope, Stream, WriterId, PravegaNodeUri};
use pravega_client::client_factory::ClientFactory;
use pravega_client_config::ClientConfigBuilder;
#[tokio::main]
async fn main() {
let scope_name = Scope::from("txnScope".to_owned());
let stream_name = Stream::from("txnStream".to_owned());
let scoped_stream = ScopedStream {
scope: scope_name.clone(),
stream: stream_name.clone(),
};
// omit the step to create scope and stream in Pravega
let config = ClientConfigBuilder::default()
.controller_uri(PravegaNodeUri::from("tcp://127.0.0.2:9091".to_string()))
.build()
.expect("creating config");
let client_factory = ClientFactory::new(config);
let mut writer = client_factory
.create_transactional_event_writer(scoped_stream.clone(), WriterId(0))
.await;
// start a transaction
let mut transaction = writer.begin().await.expect("begin transaction");
// do something with it
transaction.write_event(None, String::from("hello").into_bytes()).await.unwrap();
// commit the transaction
transaction.commit(Timestamp(0u64)).await;
}
Implementations§
source§impl TransactionalEventWriter
impl TransactionalEventWriter
sourcepub async fn begin(
&mut self
) -> Result<Transaction, TransactionalEventWriterError>
pub async fn begin( &mut self ) -> Result<Transaction, TransactionalEventWriterError>
This method opens a transaction by sending a request to Pravega controller.
sourcepub async fn get_txn(
&self,
txn_id: TxId
) -> Result<Transaction, TransactionalEventWriterError>
pub async fn get_txn( &self, txn_id: TxId ) -> Result<Transaction, TransactionalEventWriterError>
This method returns the Transaction based on the given transaction id. If the current transaction is not in open status, meaning it has been committed or aborted, this method will create a closed transaction that only contains the meta data of this transaction.
Auto Trait Implementations§
impl Freeze for TransactionalEventWriter
impl !RefUnwindSafe for TransactionalEventWriter
impl Send for TransactionalEventWriter
impl Sync for TransactionalEventWriter
impl Unpin for TransactionalEventWriter
impl !UnwindSafe for TransactionalEventWriter
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request