Skip to content

tchlyah/couchbase-financial-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Financial transactions example with Couchbase

This example shows how to implement a simple data model for financial transactions, generate data using fakeit, query data using a Spring Boot JAVA application and optimize N1QL queries using GSI indexes and prepared statements.

Start application

docker-compose is used to start everything with minimum of efforts.

First, you need to build the application, which generates a docker image using jib :

./mvnw clean install

Then, go to docker directory, and start everything :

docker-compose up --build

If you have your local instance of Couchbase or you don't want to use Docker, you can do the following :

Generate data

Fakeit is used to describe a simple financial transactions data model, and populate Couchbase with generated data.

To start generating data, make sure that you have npm installed, and Couchbase started, then execute the following :

npm install
npm start

Spring-boot application

The application is a Java REST service implemented using Spring Boot, with Swagger-UI to test requests, and Couchmove to automatically create necessary N1QL indexes and prepared statements for Couchbase.

The Couchbase repositories are implemented using stock java SDK instead of Spring Data Couchbase to demonstrate how it works.

To build and start the application :

./mvnw

Test the application

When everything is up, open your browser to http://localhost:8080/swagger-ui.html

For example, go to transaction-resource/getByBates, click on Try it out, then enter the fromDate and toDate in ISO-8601 instant format (2018-11-01T00:00:00.00Z)

Prepared queries

In addition to indexes, Couchmove also create some prepared queries that we can test using cbc-n1qlback.

Some queries are also automatically copied to Couchbase Docker instance from docker/couchbase/queries

Go to docker directory, then execute the following to open an interactive bash shell

docker-compose exec couchbase bash

To compare prepared vs simple queries, execute the following :

cbc-n1qlback -U couchbase://localhost/finance -P password -t 5 -f simple_queries.txt

cbc-n1qlback -U couchbase://localhost/finance -P password -t 5 -f prepared_queries.txt