[][src]Crate eventstore

Official Rust EventStoreDB gRPC Client.

EventStoreDB is an open-source database built from the ground up for Event Sourcing, with Complex Event Processing in Javascript.

Note: This client is currently under active development and further API changes are expected. Feedback is very welcome.

EventStoreDB Server Compatibility

This client is compatible with version 20.6.1 upwards and works on Linux, MacOS and Windows.

Server setup instructions can be found here EventStoreDB Docs, follow the docker setup for the simplest configuration.

Example

use eventstore::{ Client, EventData, ReadResult };
use futures::stream::TryStreamExt;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Foo {
    is_rust_a_nice_language: bool,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {

    // Creates a client settings for a single node configuration.
    let settings = "esdb://admin:changeit@localhost:2113".parse()?;
    let client = Client::create(settings).await?;

    let payload = Foo {
        is_rust_a_nice_language: true,
    };

    // It is not mandatory to use JSON as a data format however EventStoreDB
    // provides great additional value if you do so.
    let evt = EventData::json("language-poll", &payload)?;

    let _ = client
        .write_events("language-stream")
        .send_event(evt)
        .await?;

    let result = client
        .read_stream("language-stream")
        .start_from_beginning()
        .read_through()
        .await?;

    if let ReadResult::Ok(mut stream) = result {
        while let Some(event) = stream.try_next().await? {
            let event = event.get_original_event()
                    .as_json::<Foo>()?;

            // Do something productive with the result.
            println!("{:?}", event);
        }
    }

    Ok(())
}

Modules

prelude

Structs

AllCatchupSubscribe

Like RegularCatchupSubscribe but specific to the system stream '$all'.

Client

Represents a client to a single node. Client maintains a full duplex communication to EventStoreDB.

ClientSettings

Gathers all the settings related to a gRPC client with an EventStoreDB database. ClientSettings can only be created when parsing a connection string.

ClientSettingsParseError
ConnectToPersistentSubscription

A subscription model where the server remembers the state of the consumption of a stream. This allows for many different modes of operations compared to a regular subscription where the client hols the subscription state.

CreatePersistentSubscription

A command that creates a persistent subscription for a given group.

Credentials

Holds login and password information.

DeletePersistentSubscription

Command that deletes a persistent subscription.

DeleteStream

Command that deletes a stream. More information on Deleting stream and events.

Endpoint
EventData

Holds data of event about to be sent to the server.

FilterConf
PersistentSubEvent
PersistentSubRead

Read part of a persistent subscription, isomorphic to a stream of events.

PersistentSubscriptionSettings

Gathers every persistent subscription property.

Position

A structure referring to a potential logical record position in the EventStoreDB transaction file.

ReadAllEvents

Like ReadStreamEvents but specialized to system stream '$all'.

ReadEventResult

Represents the result of looking up a specific event number from a stream.

ReadStreamEvents

A command that reads several events from a stream. It can read events forward or backward.

RecordedEvent

Represents a previously written event.

RegularCatchupSubscribe

Subscribes to a given stream. This kind of subscription specifies a starting point (by default, the beginning of a stream). For a regular stream, that starting point will be an event number. For the system stream $all, it will be a position in the transaction file (see subscribe_to_all_from). This subscription will fetch every event until the end of the stream, then will dispatch subsequently written events.

ResolvedEvent

A structure representing a single event or an resolved link event.

StreamAcl

Represents an access control list for a stream.

StreamMetadata

Represents stream metadata with strongly types properties for system values and a dictionary-like interface for custom values.

StreamMetadataBuilder

Used to facilitate the creation of a stream's metadata.

SubscriptionRead
SubscriptionWrite
UpdatePersistentSubscription

Command that updates an already existing subscription's settings.

VersionedMetadata

Represents a stream metadata.

WriteEvents

Command that sends events to a given stream.

WriteResult

Returned after writing to a stream.

WrongExpectedVersion

Enums

CurrentRevision

Actual revision of a stream.

Error

EventStoreDB command error.

ExpectedRevision

Expected revision before a write occurs.

ExpectedVersion

Constants used for expected version control. The use of expected version can be a bit tricky especially when discussing assurances given by the GetEventStore server.

LinkTos

Determines whether any link event encountered in the stream will be resolved. See the discussion on Resolved Events for more information on this.

NakAction

Gathers every possible Nak actions.

NodePreference

Indicates which order of preferred nodes for connecting to.

Payload
PersistActionError

Enumerates all persistent action exceptions.

PersistActionResult

Represents the different scenarios that could happen when performing a persistent subscription.

ReadDirection

Represents the direction of read operation (both from '$all' and a regular stream).

ReadEventStatus

Enumeration detailing the possible outcomes of reading a stream.

ReadResult
ReadStreamError

Represents the errors that can arise when reading a stream.

ReadStreamStatus

Represents the result of reading a stream.

Retry

Represents a reconnection strategy when a connection has dropped or is about to be created.

Revision
StreamMetadataResult

Represents stream metadata as a series of properties for system data and user-defined metadata.

SubEvent

Events related to a subscription.

SystemConsumerStrategy

System supported consumer strategies for use with persistent subscriptions.

Type Definitions

Result