Package com.opencqrs.esdb.client
Class EsdbClient
java.lang.Object
com.opencqrs.esdb.client.EsdbClient
- All Implemented Interfaces:
AutoCloseable
Client SDK for the EventSourcingDB.
-
Constructor Summary
ConstructorsConstructorDescriptionEsdbClient
(URI serverUri, String accessToken, Marshaller marshaller, HttpClient.Builder httpClientBuilder) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Authenticates against the configured event store, ensuring the correct api token has been configured.void
close()
health()
Checks the healthiness of the configured event store.void
Streams existingEvent
s from the underlying event store, waiting for any new events to be published.void
ping()
Pings the configured event store, ensuring the server is runningvoid
query
(String query, RowHandler rowHandler, ErrorHandler errorHandler) Queries the underlying event store using EventQL.Reads existingEvent
s from the underlying event store.void
Reads existingEvent
s from the underlying event store.write
(List<EventCandidate> eventCandidates, List<Precondition> preconditions) Publishes the givenEventCandidate
s to the underlying event store.
-
Constructor Details
-
EsdbClient
public EsdbClient(URI serverUri, String accessToken, Marshaller marshaller, HttpClient.Builder httpClientBuilder)
-
-
Method Details
-
ping
Pings the configured event store, ensuring the server is running- Throws:
ClientException.TransportException
- in case of connection or network errorsClientException.HttpException
- in case of errors depending on the HTTP status codeClientException.MarshallingException
- in case of serialization errors, typically caused by the associatedMarshaller
ClientException
-
authenticate
Authenticates against the configured event store, ensuring the correct api token has been configured.- Throws:
ClientException.TransportException
- in case of connection or network errorsClientException.HttpException
- in case of errors depending on the HTTP status code, e.g. 401 if not authenticated successfullyClientException.MarshallingException
- in case of serialization errors, typically caused by the associatedMarshaller
ClientException
-
health
Checks the healthiness of the configured event store.- Returns:
- the health status
- Throws:
ClientException.TransportException
- in case of connection or network errorsClientException.HttpException
- in case of errors depending on the HTTP status codeClientException.MarshallingException
- in case of serialization errors, typically caused by the associatedMarshaller
ClientException
-
write
public List<Event> write(List<EventCandidate> eventCandidates, List<Precondition> preconditions) throws ClientException Publishes the givenEventCandidate
s to the underlying event store. The given preconditions must be fulfilled in order for the publication to be applied. The publication is guaranteed to be an atomic operation, that is event candidates will be published all or nothing, if preconditions hold.- Parameters:
eventCandidates
- the candidate events to be published togetherpreconditions
- preconditions that must be fulfilled, otherwiseClientException.HttpException.HttpClientException
with status code409
will be thrown- Returns:
- a list of
Event
s with all fields populated, except forEvent.hash()
- Throws:
ClientException.TransportException
- in case of connection or network errorsClientException.HttpException
- in case of errors depending on the HTTP status codeClientException.MarshallingException
- in case of serialization errors, typically caused by the associatedMarshaller
ClientException
-
observe
public void observe(String subject, Set<Option> options, Consumer<Event> eventConsumer) throws ClientException Streams existingEvent
s from the underlying event store, waiting for any new events to be published. This method will block infinitely, if no exception or error occurs. Any observed event will be passed the given event consumer synchronously, to maintain the natural event order.In order to observe all events from the underlying event store
subject
should be set to/
together withOption.Recursive
.- Parameters:
subject
- the subject to observeoptions
- a set of options controlling the result seteventConsumer
- a consumer callback for the observed events- Throws:
ClientException.InvalidUsageException
- in case of an invalidOption
usedClientException.TransportException
- in case of connection or network errorsClientException.HttpException
- in case of errors depending on the HTTP status codeClientException.MarshallingException
- in case of serialization errors, typically caused by the associatedMarshaller
ClientException
-
read
public void read(String subject, Set<Option> options, Consumer<Event> eventConsumer) throws ClientException Reads existingEvent
s from the underlying event store. All events will be passed the given event consumer synchronously, to maintain the natural event order.- Parameters:
subject
- the subject to read fromoptions
- a set of options controlling the result seteventConsumer
- a consumer callback for the read events- Throws:
ClientException.InvalidUsageException
- in case of an invalidOption
usedClientException.TransportException
- in case of connection or network errorsClientException.HttpException
- in case of errors depending on the HTTP status codeClientException.MarshallingException
- in case of serialization errors, typically caused by the associatedMarshaller
ClientException
-
read
Reads existingEvent
s from the underlying event store.- Parameters:
subject
- the subject to read fromoptions
- a set of options controlling the result set- Returns:
- a list of
Event
s, may be empty - Throws:
ClientException.InvalidUsageException
- in case of an invalidOption
usedClientException.TransportException
- in case of connection or network errorsClientException.HttpException
- in case of errors depending on the HTTP status codeClientException.MarshallingException
- in case of serialization errors, typically caused by the associatedMarshaller
ClientException
-
query
public void query(String query, RowHandler rowHandler, ErrorHandler errorHandler) throws ClientException Queries the underlying event store using EventQL.- Parameters:
query
- a valid queryrowHandler
- callback for successfully queried and transformed rows (called per row)errorHandler
- callback for non successfully queried or transformed rows (called per row)- Throws:
ClientException.TransportException
- in case of connection or network errorsClientException.HttpException
- in case of errors depending on the HTTP status codeClientException.MarshallingException
- in case of serialization errors regarding the request not the individual row, typically caused by the associatedMarshaller
ClientException
- See Also:
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-