Class EventStoreDBClient
- java.lang.Object
-
- com.eventstore.dbclient.EventStoreDBClientBase
-
- com.eventstore.dbclient.EventStoreDBClient
-
public class EventStoreDBClient extends EventStoreDBClientBase
Represents EventStoreDB client for stream operations. A client instance maintains a two-way communication to EventStoreDB. Many threads can use the EventStoreDB client simultaneously, or a single thread can make many asynchronous requests.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<WriteResult>
appendToStream(java.lang.String streamName, AppendToStreamOptions options, EventData... events)
Appends events to a given stream.java.util.concurrent.CompletableFuture<WriteResult>
appendToStream(java.lang.String streamName, AppendToStreamOptions options, java.util.Iterator<EventData> events)
Appends events to a given stream.java.util.concurrent.CompletableFuture<WriteResult>
appendToStream(java.lang.String streamName, EventData... events)
Appends events to a given stream.java.util.concurrent.CompletableFuture<WriteResult>
appendToStream(java.lang.String streamName, java.util.Iterator<EventData> events)
Appends events to a given stream.static EventStoreDBClient
create(EventStoreDBClientSettings settings)
Creates a gRPC client to EventStoreDB database.java.util.concurrent.CompletableFuture<DeleteResult>
deleteStream(java.lang.String streamName)
Deletes a given stream.java.util.concurrent.CompletableFuture<DeleteResult>
deleteStream(java.lang.String streamName, DeleteStreamOptions options)
Deletes a given stream.java.util.concurrent.CompletableFuture<StreamMetadata>
getStreamMetadata(java.lang.String streamName)
Reads stream's metadata.java.util.concurrent.CompletableFuture<StreamMetadata>
getStreamMetadata(java.lang.String streamName, ReadStreamOptions options)
Reads stream's metadata.java.util.concurrent.CompletableFuture<ReadResult>
readAll()
Reads events from the $all stream.java.util.concurrent.CompletableFuture<ReadResult>
readAll(ReadAllOptions options)
Reads events from the $all stream.org.reactivestreams.Publisher<ReadMessage>
readAllReactive()
org.reactivestreams.Publisher<ReadMessage>
readAllReactive(ReadAllOptions options)
Reads events from the $all stream.java.util.concurrent.CompletableFuture<ReadResult>
readStream(java.lang.String streamName, ReadStreamOptions options)
Reads events from a given stream.org.reactivestreams.Publisher<ReadMessage>
readStreamReactive(java.lang.String streamName)
Reads events from a given stream.org.reactivestreams.Publisher<ReadMessage>
readStreamReactive(java.lang.String streamName, ReadStreamOptions options)
Reads events from a given stream.java.util.concurrent.CompletableFuture<WriteResult>
setStreamMetadata(java.lang.String streamName, AppendToStreamOptions options, StreamMetadata metadata)
Sets a stream's metadata.java.util.concurrent.CompletableFuture<WriteResult>
setStreamMetadata(java.lang.String streamName, StreamMetadata metadata)
Sets a stream's metadata.java.util.concurrent.CompletableFuture<Subscription>
subscribeToAll(SubscriptionListener listener)
Subscriptions allow you to subscribe to $all stream and receive notifications about new events added to the stream.java.util.concurrent.CompletableFuture<Subscription>
subscribeToAll(SubscriptionListener listener, SubscribeToAllOptions options)
Subscriptions allow you to subscribe to $all stream and receive notifications about new events added to the stream.java.util.concurrent.CompletableFuture<Subscription>
subscribeToStream(java.lang.String streamName, SubscriptionListener listener)
Subscriptions allow you to subscribe to a stream and receive notifications about new events added to the stream.java.util.concurrent.CompletableFuture<Subscription>
subscribeToStream(java.lang.String streamName, SubscriptionListener listener, SubscribeToStreamOptions options)
Subscriptions allow you to subscribe to a stream and receive notifications about new events added to the stream.java.util.concurrent.CompletableFuture<DeleteResult>
tombstoneStream(java.lang.String streamName)
Tombstones a given stream.java.util.concurrent.CompletableFuture<DeleteResult>
tombstoneStream(java.lang.String streamName, DeleteStreamOptions options)
Tombstones a given stream.-
Methods inherited from class com.eventstore.dbclient.EventStoreDBClientBase
getServerVersion, isShutdown, shutdown
-
-
-
-
Method Detail
-
create
public static EventStoreDBClient create(EventStoreDBClientSettings settings)
Creates a gRPC client to EventStoreDB database.
-
appendToStream
public java.util.concurrent.CompletableFuture<WriteResult> appendToStream(java.lang.String streamName, EventData... events)
Appends events to a given stream.- Parameters:
streamName
- stream's name.events
- events to send.- Returns:
- a write result if successful.
- See Also:
WriteResult
-
appendToStream
public java.util.concurrent.CompletableFuture<WriteResult> appendToStream(java.lang.String streamName, java.util.Iterator<EventData> events)
Appends events to a given stream.- Parameters:
streamName
- stream's name.events
- events to send.- Returns:
- a write result if successful.
- See Also:
WriteResult
-
appendToStream
public java.util.concurrent.CompletableFuture<WriteResult> appendToStream(java.lang.String streamName, AppendToStreamOptions options, EventData... events)
Appends events to a given stream.- Parameters:
streamName
- stream's name.options
- append stream request's options.events
- events to send.- Returns:
- a write result if successful.
- See Also:
WriteResult
-
appendToStream
public java.util.concurrent.CompletableFuture<WriteResult> appendToStream(java.lang.String streamName, AppendToStreamOptions options, java.util.Iterator<EventData> events)
Appends events to a given stream.- Parameters:
streamName
- stream's name.options
- append stream request's options.events
- events to send.- Returns:
- a write result if successful.
- See Also:
WriteResult
-
setStreamMetadata
public java.util.concurrent.CompletableFuture<WriteResult> setStreamMetadata(java.lang.String streamName, StreamMetadata metadata)
Sets a stream's metadata.- Parameters:
streamName
- stream's name.metadata
- stream's metadata- Returns:
- a write result if successful.
- See Also:
WriteResult
-
setStreamMetadata
public java.util.concurrent.CompletableFuture<WriteResult> setStreamMetadata(java.lang.String streamName, AppendToStreamOptions options, StreamMetadata metadata)
Sets a stream's metadata.- Parameters:
streamName
- stream's name.options
- append stream request's options.metadata
- stream's metadata- Returns:
- a write result if successful.
- See Also:
WriteResult
-
readStream
public java.util.concurrent.CompletableFuture<ReadResult> readStream(java.lang.String streamName, ReadStreamOptions options)
Reads events from a given stream. The reading can be done forwards and backwards.- Parameters:
streamName
- stream's name.options
- read request's operations.
-
readStreamReactive
public org.reactivestreams.Publisher<ReadMessage> readStreamReactive(java.lang.String streamName)
Reads events from a given stream. The reading can be done forwards and backwards.- Parameters:
streamName
- stream's name.
-
readStreamReactive
public org.reactivestreams.Publisher<ReadMessage> readStreamReactive(java.lang.String streamName, ReadStreamOptions options)
Reads events from a given stream. The reading can be done forwards and backwards.- Parameters:
streamName
- stream's name.options
- read request's operations.
-
getStreamMetadata
public java.util.concurrent.CompletableFuture<StreamMetadata> getStreamMetadata(java.lang.String streamName)
Reads stream's metadata.- Parameters:
streamName
- stream's name.- See Also:
StreamMetadata
-
getStreamMetadata
public java.util.concurrent.CompletableFuture<StreamMetadata> getStreamMetadata(java.lang.String streamName, ReadStreamOptions options)
Reads stream's metadata.- Parameters:
streamName
- stream's name.options
- read request's operations.- See Also:
StreamMetadata
-
readAll
public java.util.concurrent.CompletableFuture<ReadResult> readAll()
Reads events from the $all stream. The reading can be done forwards and backwards.
-
readAll
public java.util.concurrent.CompletableFuture<ReadResult> readAll(ReadAllOptions options)
Reads events from the $all stream. The reading can be done forwards and backwards.- Parameters:
options
- options of the read $all request.
-
readAllReactive
public org.reactivestreams.Publisher<ReadMessage> readAllReactive()
-
readAllReactive
public org.reactivestreams.Publisher<ReadMessage> readAllReactive(ReadAllOptions options)
Reads events from the $all stream. The reading can be done forwards and backwards.- Parameters:
options
- options of the read $all request.
-
subscribeToStream
public java.util.concurrent.CompletableFuture<Subscription> subscribeToStream(java.lang.String streamName, SubscriptionListener listener)
Subscriptions allow you to subscribe to a stream and receive notifications about new events added to the stream. You provide an even handler and an optional starting point to the subscription. The handler is called for each event from the starting point onward. If events already exist, the handler will be called for each event one by one until it reaches the end of the stream. From there, the server will notify the handler whenever a new event appears.- Parameters:
streamName
- stream's name.listener
- consumes a subscription's events.- Returns:
- a subscription handle.
-
subscribeToStream
public java.util.concurrent.CompletableFuture<Subscription> subscribeToStream(java.lang.String streamName, SubscriptionListener listener, SubscribeToStreamOptions options)
Subscriptions allow you to subscribe to a stream and receive notifications about new events added to the stream. You provide an even handler and an optional starting point to the subscription. The handler is called for each event from the starting point onward. If events already exist, the handler will be called for each event one by one until it reaches the end of the stream. From there, the server will notify the handler whenever a new event appears.- Parameters:
streamName
- stream's name.listener
- consumes a subscription's events.options
- a subscription request's options.- Returns:
- a subscription handle.
-
subscribeToAll
public java.util.concurrent.CompletableFuture<Subscription> subscribeToAll(SubscriptionListener listener)
Subscriptions allow you to subscribe to $all stream and receive notifications about new events added to the stream. You provide an even handler and an optional starting point to the subscription. The handler is called for each event from the starting point onward. If events already exist, the handler will be called for each event one by one until it reaches the end of the stream. From there, the server will notify the handler whenever a new event appears.- Parameters:
listener
- consumes a subscription's events.- Returns:
- a subscription handle.
-
subscribeToAll
public java.util.concurrent.CompletableFuture<Subscription> subscribeToAll(SubscriptionListener listener, SubscribeToAllOptions options)
Subscriptions allow you to subscribe to $all stream and receive notifications about new events added to the stream. You provide an even handler and an optional starting point to the subscription. The handler is called for each event from the starting point onward. If events already exist, the handler will be called for each event one by one until it reaches the end of the stream. From there, the server will notify the handler whenever a new event appears.- Parameters:
listener
- consumes a subscription's events.options
- subscription to $all request's options.- Returns:
- a subscription handle.
-
deleteStream
public java.util.concurrent.CompletableFuture<DeleteResult> deleteStream(java.lang.String streamName)
Deletes a given stream.Makes use of Truncate before. When a stream is deleted, its Truncate before is set to the stream's current last event number. When a deleted stream is read, the read will return a StreamNotFound error. After deleting the stream, you are able to write to it again, continuing from where it left off.
Note: Deletion is reversible until the scavenging process runs.- Parameters:
streamName
- stream's name- Returns:
- if successful, delete result.
- See Also:
DeleteResult
-
deleteStream
public java.util.concurrent.CompletableFuture<DeleteResult> deleteStream(java.lang.String streamName, DeleteStreamOptions options)
Deletes a given stream.Makes use of Truncate before, When a stream is deleted, its Truncate before is set to the stream's current last event number. When a soft deleted stream is read, the read will return a StreamNotFound error. After deleting the stream, you are able to write to it again, continuing from where it left off.
Note: soft deletion is reversible until the scavenging process runs.- Parameters:
streamName
- stream's nameoptions
- delete stream request's options.- Returns:
- if successful, delete result.
- See Also:
DeleteResult
-
tombstoneStream
public java.util.concurrent.CompletableFuture<DeleteResult> tombstoneStream(java.lang.String streamName)
Tombstones a given stream.Writes a tombstone event to the stream, permanently deleting it. The stream cannot be recreated or written to again. Tombstone events are written with the event's type '$streamDeleted'. When a tombstoned stream is read, the read will return a StreamDeleted error.
- Parameters:
streamName
- a stream's name.- Returns:
- if successful, delete result.
- See Also:
DeleteResult
-
tombstoneStream
public java.util.concurrent.CompletableFuture<DeleteResult> tombstoneStream(java.lang.String streamName, DeleteStreamOptions options)
Tombstones a given stream.Writes a tombstone event to the stream, permanently deleting it. The stream cannot be recreated or written to again. Tombstone events are written with the event's type '$streamDeleted'. When a tombstoned stream is read, the read will return a StreamDeleted error.
- Parameters:
streamName
- a stream's name.options
- delete stream request's options.- Returns:
- if successful, delete result.
- See Also:
DeleteResult
-
-