Skip to content

perbergman/astra1

Repository files navigation

Getting Started with Apache Cassandra™ and Java using DataStax Astra

50 minutes, Intermediate, Start Building

This provides an example REST backend built in Java using Spring Boot for use with the Getting Started with Astra UI.

image

Objectives

  • How to connect to Astra via the Secure Connect Bundle
  • How to manage a Cassandra Session within a JAVA web application

How this Works

This is an example of a Spring Boot Microservice for use with the Astra Getting Started UI which is found here.

Get Started

To build and play with this app, follow the build instructions that are located here: https://github.com/DataStax-Examples/getting-started-with-astra-java

Prerequisites

Let's do some initial setup.

DataStax Astra

  1. Create a DataStax Astra account if you don't already have one: image

  2. On the home page. Locate the button Add Database image

  3. Pick free plan and a region close to you, click configure. image image

  4. Define a database name, keyspace name and credentials (Take note of the DB Password) image

  5. Your Astra DB will be ready when the status will change from Pending to Active 💥💥💥 image

  6. Locate the combo Organization: <Your email> on the top navigation. In the drop down menu, click your current organization. image

  7. Scroll down to the bottom of the page and locate Service Account in Security Settings and select Copy Credentials as shown below. image

Github

  1. Click Use this template at the top of the GitHub Repository: image

  2. Enter a repository name and click 'Create repository from template': image

  3. Clone the repository: image

🚀 Getting Started Paths:

Make sure you've completed the prerequisites before starting this step

Running on your local machine

Make sure that you have:

  • Java 11+
  • An Astra compatible Java driver, instructions may be found here to install this locally.
  • An Astra database with the CQL schema located in schema.cql already added.
  • The username, password, keyspace name, and secure connect bundle downloaded from your Astra Database. For information on how to obtain these credentials please read the documentation found here.

This application is a Spring Boot web application. This sample can be run from the root directory using:

cd getting-started-with-astra-java

mvn spring-boot:run

This will startup the application running on http://localhost:8080

You will know that you are up and working when you get the following in your terminal window:

16:23:01.569 INFO  com.datastax.astra.GettingStartedWithAstra  : Started GettingStartedWithAstra in 1.851 seconds (JVM running for 2.39)

Access the API documentation from a browser

http://localhost:8080

Note: If you want to change the listening port of the application, locate the file src/main/resources/application.yml and change key server.port

Setup the user interface to use this backend

To setup the UI to connect to Java backend define a .env file in the getting-started-with-astra-ui project main directory. Inside the file it should have one entry pointing to this project's API endpoint:

BASE_ADDRESS=http://localhost:8080/api

Once you start that project with a npm run build it will point the UI to the backend API which will then be using Astra as a database. When you first connect to the UI, a dialog box will open asking for Astra connection information.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published