Search code examples
spring-booteventstoredb

Connecting to EventStoreDB from Spring Boot


I have EventStoreDB running in a local Kubernetes cluster, installed using this Helm chart. Port-forwarding on 2113 allows me to access the admin dashboard as expected at localhost:2113/web/index.html

I am now trying to connect to this running instance from a Spring Boot microservice running in the same cluster. I am using this dependency of the EventStoreDB client

<dependency>
  <groupId>com.eventstore</groupId>
  <artifactId>db-client-java</artifactId>
  <version>5.2.0</version>
  <scope>provided</scope>
</dependency>

And I have the following code snippet which attempts to establish a connection and publish an event. However when triggering this, appendToStream() hangs indefinitely

EventStoreDBClientSettings settings = EventStoreDBClientSettings.builder()
  .addHost("localhost", 1113)
  .tls(false)
  .defaultCredentials("admin", "changeit")
  .maxDiscoverAttempts(1)
  .buildConnectionSettings();
EventStoreDBClient client = EventStoreDBClient.create(settings);
AppendToStreamOptions appendToStreamOptions = AppendToStreamOptions.get().expectedRevision(ExpectedRevision.noStream());
client.appendToStream("some-stream", appendToStreamOptions, eventData).get();

And for clarity, here is the declaration of eventData, where {myObject} is a domain object.

final EventData eventData = EventData.builderAsJson(UUID.randomUUID(), "some-event", {myObject}).build();

I have also tried using connection strings rather than the client to establish the connection settings, as is suggested in several places.

String connectionString = esdb://localhost:2113?tls=false
EventStoreDBConnectionString.parseOrThrow(connectionString);

I have also tried using tcp connection strings

ConnectTo=tcp://localhost:1113; UseSslConnection=false;

However I believe these are now unsupported in favor of using the client, as suggested here

No exceptions are thrown, the execution just hangs indefinitely which is presumably caused by appendToStream().get() awaiting a response from the CompleteableFuture.

The admin dashboard shows no connections and no streams when viewed in a browser.

Note that I have tried both ports 1113 and 2113 in all cases. Does anyone have any ideas why I can't connect or publish an event?

EDIT: JDK 21.0.1 and ESDB 4.1.1.0


Solution

  • The issue is probably caused by the version of the esdb server referenced in the Helm chart. The Helm chart points to an old version of esdb that is no longer supported and instead should point to eventstore/eventstore:latest.