Creating a New Java App

If you haven't already, you'll first need to set up your development environment and ensure you have a Grainite server running (can be running locally in a Docker container).

1. Develop your Application

Generate an Application

First, generate the config file for the application.

gx gen config app.yaml

Then, run the below command to generate the project and its files based on the configuration This will include a pom.xml file for building with Maven. Optional: If you happen to already have an application which uses Maven or Gradle with a pom.xml or build.gradle file or for some other reason choose not to use gx gen all , further instructions can be found at the end of the page.

gx gen all -M
pageCode / Project Generation Commands (gx gen)

Implement the Application Logic

Implement your action handlers, client programs, and any other parts of your app's functionality. You may use the API pages here or the Grainite Javadocs for reference.

2. Build and Load the Application

Build the application using Maven.

mvn package

Then, load the application onto the Grainite server.

gx load
pageApp Load (gx load)

4. Run the load

Run the command below to start a sample load generator which will send events to the application.

java -cp target/food_app-jar-with-dependencies.jar org.sample.food_app.Client

<lib path> can generally be found at `$HOME/grainite/lib`.

5. Observe the Application

  • Print all events in the topic: gx topic dump orders_topic

  • Print all grains in the table: gx table dump orders_table

pageTopic Commands (gx topic)pageTable Commands (gx table)

Refer to the GX CLI document for more in-depth information about gx.

pagegx CLI

Optional: Build Existing Application

If you happen to already have an application with a pom.xml or build.gradle file or for some other reason choose not to use gx gen all (which can generate these for you), please follow the instructions below.

In your application's pom.xml, add the following dependency and repository:

pom.xml
<dependencyManagement> 
  ... 
  <dependency>
    <groupId>com.grainite</groupId>
    <artifactId>libgrainite</artifactId>
    <version>latest</version>
  </dependency>
</dependencyManagement>

<repositories>
   ...
  <repository>
    <id>gitlab-maven</id>
    <url>https://gitlab.com/api/v4/projects/41132986/packages/maven</url>
  </repository>
</repositories>

Last updated