Skip to content

Latest commit

 

History

History

document-nosql

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

MicroProfile generated Application

Introduction

MicroProfile Starter has generated this MicroProfile application for you.

The generation of the executable jar file can be performed by issuing the following command

mvn clean package

This will create an executable jar file eclipse-store.jar within the target maven folder. This can be started by executing the following command

java -jar target/eclipse-store.jar

Liberty Dev Mode

During development, you can use Liberty's development mode (dev mode) to code while observing and testing your changes on the fly. With the dev mode, you can code along and watch the change reflected in the running server right away; unit and integration tests are run on pressing Enter in the command terminal; you can attach a debugger to the running server at any time to step through your code.

mvn liberty:dev

To launch the test page, open your browser at the following URL

http://localhost:9080/index.html  

Specification examples

By default, there is always the creation of a JAX-RS application class to define the path on which the JAX-RS endpoints are available.

Also, a simple Hello world endpoint is created, have a look at the class HelloController.

More information on MicroProfile can be found here

Switching between database

Check the file "microprofile-config.properties" and comment on one of the "jnosql.document.provider" keys.

Couchbase (Default)

Couchbase Server, originally known as Membase, is an open-source, distributed multi-model NoSQL document-oriented database software package optimized for interactive applications. These applications may serve many concurrent users by creating, storing, retrieving, aggregating, manipulating and presenting data.

Configurations

  1. Install docker: https://www.docker.com/
  2. https://hub.docker.com/r/couchbase/server/
  3. Run docker command:
docker run -d --name db -p 8091-8097:8091-8097 -p 9123:9123 -p 11207:11207 -p 11210:11210 -p 11280:11280 -p 18091-18097:18091-18097 couchbase
  1. Access: http://localhost:8091/ui/index.html
  2. Select the option "Setup New Cluster"
  3. Define "root" as Admin username
  4. Define "123456" as Password
  5. Define "localhost" as Cluster Name
  6. Accept the terms and conditions
  7. Go to "Buckets" session
  8. Create Bucket "beers" using the "Add Bucket" Option
  9. Click at "beers"
  10. Add "Hero" and "Villain" as Collection
  11. Go to Query session and execute: CREATE PRIMARY INDEX #primary ON factory._default.beer

MongoDB

MongoDB is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas.

Configurations

  1. Install docker: https://www.docker.com/
  2. https://hub.docker.com/r/couchbase/server/
  3. Run docker command:
docker run -d --name mongodb-instance -p 27017:27017 mongo

Testing the API

Inserting:

curl --location --request POST 'http://localhost:9080/beers/random'
curl --location 'http://localhost:9080/beers/'
curl --location 'http://localhost:9080/beers/?page=1&hop=Magnum'
curl --location 'http://localhost:9080/beers/?page=1&hop=Magnum&malt=Vienna'