Package com.opencqrs.esdb.client
Class EsdbClient
java.lang.Object
com.opencqrs.esdb.client.EsdbClient
- All Implemented Interfaces:
AutoCloseable
Client SDK for the EventSourcingDB.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEsdbClient(URI serverUri, String accessToken, Marshaller marshaller, HttpClient.Builder httpClientBuilder) -
Method Summary
Modifier and TypeMethodDescriptionvoidAuthenticates against the configured event store, ensuring the correct api token has been configured.voidclose()health()Checks the healthiness of the configured event store.voidStreams existingEvents from the underlying event store, waiting for any new events to be published.voidping()Pings the configured event store, ensuring the server is runningvoidquery(EventQuery query, EventQueryRowHandler rowHandler, EventQueryErrorHandler errorHandler) Queries the underlying event store using EventQL.Reads existingEvents from the underlying event store.voidReads existingEvents from the underlying event store.write(List<EventCandidate> eventCandidates, List<Precondition> preconditions) Publishes the givenEventCandidates to the underlying event store.
-
Field Details
-
EVENT_TYPE_PING_RECEIVED
- See Also:
-
EVENT_TYPE_API_TOKEN_VERIFIED
- See Also:
-
-
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 associatedMarshallerClientException
-
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 associatedMarshallerClientException
-
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 associatedMarshallerClientException
-
write
public List<Event> write(List<EventCandidate> eventCandidates, List<Precondition> preconditions) throws ClientException Publishes the givenEventCandidates 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.HttpClientExceptionwith status code409will be thrown- Returns:
- a list of
Events 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 associatedMarshallerClientException
-
observe
public void observe(String subject, Set<Option> options, Consumer<Event> eventConsumer) throws ClientException Streams existingEvents 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
subjectshould 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 invalidOptionusedClientException.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 associatedMarshallerClientException
-
read
public void read(String subject, Set<Option> options, Consumer<Event> eventConsumer) throws ClientException Reads existingEvents 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 invalidOptionusedClientException.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 associatedMarshallerClientException
-
read
Reads existingEvents from the underlying event store.- Parameters:
subject- the subject to read fromoptions- a set of options controlling the result set- Returns:
- a list of
Events, may be empty - Throws:
ClientException.InvalidUsageException- in case of an invalidOptionusedClientException.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 associatedMarshallerClientException
-
query
public void query(EventQuery query, EventQueryRowHandler rowHandler, EventQueryErrorHandler errorHandler) throws ClientException Queries the underlying event store using EventQL.- Parameters:
query- theEventQueryto executerowHandler- 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 associatedMarshallerClientException- See Also:
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-