Crate eventstore_tcp [−] [src]
Tokio-based EventStore client library in it's early stages.
Currently the most interesting API is the tokio_service::service::Service
implemented by
client::Client
, which allows sending values of Package
to get back a Future
of a response
Package
. Package
is the name for a frame in the protocol. See it's documentation for more
information.
You can build values of Package
using builder::Builder
and it's functions. Actual payloads
are described as Message
enum.
The protocol is multiplexed so you can have multiple (hard limit is 128 currently) calls going
at any point in time. Current implementation is based on tokio_proto::multiplex
, at the
moment using a custom fork. It does not yet support tokio_proto::streaming::multiplex
which is
needed to support subscriptions.
Panics
There should not be any panicing now that adapted
and raw
are separate.
Simplest example
Example of writing to the database and simple handling of the response.
extern crate futures; extern crate tokio_core; extern crate tokio_proto; extern crate tokio_service; extern crate eventstore_tcp; use std::net::SocketAddr; use futures::Future; use tokio_core::reactor::Core; use tokio_service::Service; use eventstore_tcp::{EventStoreClient, Builder, AdaptedMessage, StreamVersion, ContentType}; fn main() { let addr = "127.0.0.1:1113".parse::<SocketAddr>().unwrap(); let mut core = Core::new().unwrap(); // connecting the client returns a future for an EventStoreClient // which implements tokio_service::Service let client = EventStoreClient::connect(&addr, &core.handle()); let value = client.and_then(|client| { // once the connection is made and EventStoreClient (`client`) // is created, send a WriteEvents request: client.call(Builder::write_events() .stream_id("my_stream-1") .expected_version(StreamVersion::from(42)) .new_event() .event_type("meaning_of_life") .data("{ 'meaning': 42 }".as_bytes()) .data_content_type(ContentType::Json) .done() .build_package(None, None)) // call returns a future representing the response }).and_then(|resp| { // By default, `resp` is a `Package` that contains the raw protobuf defined message // (`RawMessage`). It is possible to refine it into AdaptedMessage which can fail: match resp.message.try_adapt().unwrap() { AdaptedMessage::WriteEventsCompleted(Ok(_)) => println!("Event was written successfully"), AdaptedMessage::WriteEventsCompleted(Err(fail)) => println!("Event writing failed: {:?}", fail), unexpected => println!("Unexpected response: {:#?}", unexpected), }; Ok(()) }); core.run(value).unwrap(); }
More examples can be found in the aspiring command line tool under examples/testclient
.
Reexports
pub use raw::RawMessage; |
pub use raw::client_messages::WriteEvents; |
pub use raw::client_messages::ResolvedIndexedEvent; |
pub use raw::client_messages::EventRecord; |
pub use raw::client_messages::ReadAllEvents; |
pub use raw::client_messages::mod_NotHandled::NotHandledReason; |
pub use raw::client_messages::mod_NotHandled::MasterInfo; |
pub use adapted::AdaptedMessage; |
pub use package::Package; |
pub use builder::Builder; |
Modules
adapted |
Adapted or refined types providing a much more oxidized API for handling the messages in the protocol. |
builder |
Builders to help building requests. |
codec |
|
package |
Frame and MessageContainer |
raw |
Raw module contains the enumeration |
Structs
EventStoreClient |
|
StreamVersion |
|
UsernamePassword |
Username and password authentication token embedded in requests as there is no concept of session in the TCP protocol, every request must be authenticated. |
Enums
ContentType |
Content type of the event |
EventNumber |
|
ExpectedVersion |
|
LogPosition |
Global unique position in the EventStore, used when reading all events. Range -1..i64::max_value() |
ReadDirection |
The direction in which events are read. |