Skip to content

Run the example

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

This page guides you through running the Java transaction graph example.

Clone the repository

  1. Clone the Aerospike Graph repository.

    Open a terminal and clone the repository:

    Terminal window
    git clone https://github.com/aerospike/aerospike-graph.git
    cd aerospike-graph
    Cloning into 'aerospike-graph'...
    remote: Enumerating objects: 1234, done.
    remote: Counting objects: 100% (1234/1234), done.
    remote: Compressing objects: 100% (567/567), done.
    remote: Total 1234 (delta 456), reused 987 (delta 345)
    Receiving objects: 100% (1234/1234), 2.34 MiB | 5.67 MiB/s, done.
    Resolving deltas: 100% (456/456), done.
    Example response

Start Aerospike Graph Service

  1. Start the Docker containers.

    From the repository root, start AGS and Aerospike Database:

    Terminal window
    docker compose up -d
    [+] Running 3/3
    ✔ Network asgraph_net Created
    ✔ Container aerospike-db Started
    ✔ Container aerospike-graph-service Started
    ✔ Container asgraph-zipkin Started
    Example response
  2. Wait for services to be ready.

    AGS waits for the database to complete startup before accepting connections. This typically takes 10 to 20 seconds.

  3. Check the AGS logs.

    Terminal window
    docker logs aerospike-graph-service
    Found named graphs: []
    Setting gremlinPool to 56 and threadPoolWorker to 7.
    ...
    Successfully configured Aerospike Graph Service.
    [INFO] c.a.f.r.FireflyServer - Warmup is complete.
    Example response

If the containers fail to start, ensure no other services are using ports 8182, 3000, or 9411. You can stop conflicting services or modify the port mappings in docker-compose.yaml.

Build and run the Java application

  1. Navigate to the Java basic example directory.

    Terminal window
    cd java/basic
  2. Build the project with Maven.

    Compile the project and package it into an executable JAR file:

    Terminal window
    mvn clean install
    [INFO] Scanning for projects...
    [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 38, column 21
    [INFO] Building ags-java-example 1.0
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] --- clean:3.2.0:clean (default-clean) @ ags-java-example ---
    [INFO] --- resources:3.3.1:resources (default-resources) @ ags-java-example ---
    [INFO] --- compiler:3.13.0:compile (default-compile) @ ags-java-example ---
    [INFO] Compiling 1 source file with javac [debug target 11] to target/classes
    [INFO] --- surefire:3.3.1:test (default-test) @ ags-java-example ---
    [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    [INFO] --- jar:3.4.1:jar (default-jar) @ ags-java-example ---
    [INFO] --- assembly:3.7.1:single (default) @ ags-java-example ---
    [INFO] --- install:3.1.2:install (default-install) @ ags-java-example ---
    [INFO] BUILD SUCCESS
    Example response
  3. Run the Java application.

    Execute the packaged JAR file:

    Terminal window
    java -jar target/ags-java-example-1.0-jar-with-dependencies.jar
    Connected to Aerospike Graph Service; Adding Data...
    Adding some users, accounts and transactions
    Data written successfully...
    QUERY 1: Transactions initiated by Alice:
    Transaction Amount: 200, Receiver Account ID: A2
    Transaction Amount: 271, Receiver Account ID: A2
    Transaction Amount: 29, Receiver Account ID: A2
    Transaction Amount: 653, Receiver Account ID: A2
    Transaction Amount: 814, Receiver Account ID: A2
    Transaction Amount: 684, Receiver Account ID: A4
    Transaction Amount: 774, Receiver Account ID: A5
    Transaction Amount: 513, Receiver Account ID: A1
    Transaction Amount: 993, Receiver Account ID: A4
    Transaction Amount: 379, Receiver Account ID: A3
    Transaction Amount: 199, Receiver Account ID: A4
    Transaction Amount: 544, Receiver Account ID: A3
    Transaction Amount: 233, Receiver Account ID: A1
    Transaction Amount: 41, Receiver Account ID: A3
    QUERY 2: Total transaction amounts initiated by users:
    {A1=6327, A2=4999, A3=2747, A4=3590, A5=5107}
    QUERY 3: Users who transferred greater than 100 to Alice:
    User: {name=[Bob]}
    User: {name=[Bob]}
    User: {name=[Bob]}
    User: {name=[Bob]}
    User: {name=[Bob]}
    User: {name=[Diana]}
    User: {name=[Diana]}
    User: {name=[Diana]}
    User: {name=[Charlie]}
    User: {name=[Alice]}
    User: {name=[Alice]}
    User: {name=[Eve]}
    User: {name=[Eve]}
    User: {name=[Eve]}
    QUERY 4: Properties of Bob:
    name : Bob
    userId : U2
    age : 35
    Dropping Dataset.
    Closing Connection...
    Example response

The example creates five users (Alice, Bob, Charlie, Diana, Eve), five accounts, and 50 random transactions. It then cleans up by dropping all vertices and edges before closing the connection.

Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?