A sample online banking application that uses the Cloud Spanner advanced features, including transactions, AI integration, full-text search, and BigQuery federated queries.
This sample requires Java and Maven for building the application.
The accompanying codelab for this sample is: https://codelabs.developers.google.com/spanner-online-banking-app
ℹ️ Note that you can use Google Cloud Shell instead of developing locally. In that case skip step #2 and #3 below.
-
Create a project in the Google Cloud Platform console.
-
Install and configure the gcloud CLI.
-
Follow the Java development environment setup instructions.
-
Authenticate with the gcloud CLI:
gcloud auth application-default login- Enable the required APIs (Spanner, Vertex AI, and BigQuery) for your project:
gcloud services enable spanner.googleapis.com
gcloud services enable aiplatform.googleapis.com
gcloud services enable bigquery.googleapis.com
gcloud services enable bigqueryconnection.googleapis.com- Create a Cloud Spanner instance:
gcloud spanner instances create "cloudspanner-onlinebanking" \
--config=regional-us-central1 \
--description="Spanner Online Banking" \
--nodes=1 \
--edition=ENTERPRISE \
--default-backup-schedule-type=NONE- Create a BigQuery table and Spanner connection:
gcloud components install bq
bq mk --location=us-central1 MarketingCampaigns
bq mk --table MarketingCampaigns.CustomerSegments CampaignId:STRING,CampaignName:STRING,CustomerId:INT64
export GOOGLE_CLOUD_PROJECT=<PROJECT_ID>
bq mk --connection \
--connection_type=CLOUD_SPANNER \
--properties="{\"database\": \"projects/$GOOGLE_CLOUD_PROJECT/instances/cloudspanner-onlinebanking/databases/onlinebanking\", \"useParallelism\": true, \"useDataBoost\": true}" \
--location=us-central1 \
spanner-connection
bq query --use_legacy_sql=false '
INSERT INTO MarketingCampaigns.CustomerSegments (CampaignId, CampaignName, CustomerId)
VALUES
("campaign1", "Spring Promotion", 1),
("campaign1", "Spring Promotion", 3),
("campaign1", "Spring Promotion", 5),
("campaign1", "Spring Promotion", 7),
("campaign1", "Spring Promotion", 9),
("campaign1", "Spring Promotion", 11)
'- Build the application using the following Maven command:
mvn package- Set the instance and database id via environment variables:
export SPANNER_INSTANCE=cloudspanner-onlinebanking
export SPANNER_DATABASE=onlinebanking- Run the online banking application to display the available commands:
java -jar target/onlinebanking.jarCommand output:
Online Banking Application 1.0.0
Usage:
java -jar target/onlinebanking.jar <command> [command_option(s)]
Examples:
java -jar target/onlinebanking.jar create
- Create a sample Cloud Spanner database and schema in your project.
java -jar target/onlinebanking.jar insert
- Insert sample Customers, Accounts, and Transactions into the database.
java -jar target/onlinebanking.jar categorize
- Use AI to categorize transactions in the database.
java -jar target/onlinebanking.jar query balance 1
- Query customer account balance(s) by customer id.
java -jar target/onlinebanking.jar query email madi
- Find customers by email using fuzzy search.
java -jar target/onlinebanking.jar query spending 1 groceries
- Query customer spending by customer id and category using full-text search.
java -jar target/onlinebanking.jar campaign campaign1 5000
- Use Federated queries (BigQuery) to find customers that match a marketing campaign by name based on a recent spending threshold.
java -jar target/onlinebanking.jar delete
- Delete sample Cloud Spanner database.- Run through the available commands, starting with
createandinsert, then try the advanced queries and other features
ℹ️ Note that the tests require a Spanner instance to have already been created. And the tests will create a new database with random characters to avoid deleting the database if already in use.
- Configure the environment variables for the test:
export SPANNER_TEST_INSTANCE=cloudspanner-onlinebanking
export SPANNER_TEST_DATABASE=onlinebanking- Run the tests:
mvn integration-test- Delete the Spanner instance:
gcloud spanner instances delete cloudspanner-onlinebanking- Delete the BigQuery connection and dataset:
bq rm --connection --location=us-central1 spanner-connection
bq rm -r MarketingCampaigns