Skip to content

Files

Latest commit

0083437 · Mar 6, 2024

History

History

esdb-sample-springboot

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 30, 2024
Feb 8, 2024
Jan 30, 2024
Jan 30, 2024
Mar 6, 2024
Feb 8, 2024
Jan 30, 2024
Jan 30, 2024
Jan 30, 2024
Jan 30, 2024
Jan 30, 2024
Feb 8, 2024
Jan 30, 2024

Spring Boot Sample: Hello, World!

This guide shows you how to stand up a sample Hello World application, built with Spring Boot, that connects to EventStoreDB.

The sample exposes a simple HTTP endpoint http://localhost:8080/hello-world?visitor={visitor} that shows how to append to and read from a stream in EventStoreDB.

When a visitor says hello via hello-world?visitor={visitor}, an event is appended to a stream to record the fact they have been greeted.

The stream is then read from beginning to end to return the full log of visitors on each call to /hello-world?visitor={visitor}.

You can see how this is done in the source code here.

Prerequisites

Before running the application, make sure you have the following installed on your system:

Running The Sample

  1. Clone the repository:

    git clone https://github.com/EventStore/samples.git
    cd samples/Quickstart/Java/esdb-sample-springboot
    
  2. Run the application and database using Docker Compose:

    docker compose up -d
    
  3. Verify the containers are up and running:

    docker compose ps
    

    Output:

    NAME                                              IMAGE                          ...   STATUS                   PORTS
    esdb-sample-springboot-esdb-local-1               eventstore/eventstore:latest   ...   Up 7 seconds (healthy)   1112-1113/tcp, 0.0.0.0:2113->2113/tcp
    esdb-sample-springboot-esdb-sample-springboot-1   esdb-sample-springboot         ...   Up 7 seconds             0.0.0.0:8080->8080/tcp
    
  4. Test the application:

    Say hello as Ouro:

    curl "localhost:8080/hello-world?visitor=Ouro"
    

    Say hello as YourName:

    curl "localhost:8080/hello-world?visitor=YourName"
    

    Output:

    1 visitors have been greeted, they are: [Ouro]
    
    2 visitors have been greeted, they are: [Ouro, YourName]
    
  5. To stop and remove the containers, use:

    docker compose down
    

Additional Information

For more in-depth and detailed examples of using EventStoreDB and the Java Client, refer to: