Skip to content

SQL Store showcasing capabilities of Infinispan Table and Query caches with persistence

Notifications You must be signed in to change notification settings

infinispan-demos/infinispan-sqlstore-demo

Repository files navigation

Infinispan

Infinispan SQL Store Demo with Quarkus

Description

Retail Catalogue

Retail Catalogue is a very simple Quarkus application that persists data in a Postgresql database.

'commands' endpoint displays the content of the database model.

[
    {
        "id": 5,
        "buyer": {
            "id": 4,
            "country": "Spain",
            "email": "mfrechilla@quarkus.io",
            "name": "Maria Rosario Frechilla",
            "phone": "+34 666"
        },
    "products": [
            {
                "id": 1,
                "code": "c123",
                "name": "Skirt Party",
                "price": 50,
                "stock": 20
            },
            {
                "id": 2,
                "code": "c456",
                "name": "Pants Party",
                "price": 20,
                "stock": 10
            },
            {
                "id": 3,
                "code": "c789",
                "name": "Dress Party",
                "price": 90,
                "stock": 20
            }
            ],
          "promotion": true
        }
]

Inmemory Catalogue

Inmemory Catalogue creates two SQL Cache Stores with Infinispan on startup.

  1. catalogue-table-store is a table sql store persisted cache that maps to the RetailProduct table
  2. sold-products-query-storeis a query sql store persisted cache that joins information across multiple tables.

Both caches use indexing.

The application exposes 3 endpoints:

  • catalogue: Lists the catalogue content. Can filter by name, stock units and prices using query parameters.
  • catalogue/{code}: Displays the catalogue product by code
  • sales: Lists the products than have been sold. Filter can be done name of the product and country.

Dev mode

  • Run Infinispan and Postgresql in the same network with docker
docker-compose up

Dev services are disabled since the Infinispan and Postresql need to be in the same docker network and Infinispan access the Postgresql database directly to load the data into the caches.

  • Run Retail Catalogue and Store
cd infinispan-sqlstore-demo/retail-catalogue 
./mvnw quarkus:dev 
  • Run Infinispan In-memory catalogue
cd infinispan-sqlstore-demo/inmemory-catalogue 
./mvnw quarkus:dev 

Links

Additional resources and useful links:

Deploy Minikube

  1. Install and start Minikube
 minikube start --driver=virtualbox --cpus 4 --memory "8192mb"
  1. Create Kubernetes Secret sqlstore-credentials
kubectl create secret generic clients-credentials 
--from-literal=db-username=infinispan 
--from-literal=db-password=secret
--from-literal=infinispan-username=admin 
--from-literal=infinispan-password=secret
  1. Deploy Postgresql
kubectl apply -f postgres.yaml
  1. Build and deploy Retail Catalogue
eval $(minikube -p minikube docker-env)
./mvnw clean package -Dquarkus.kubernetes.deploy=true -DskipTests=true 

# Export the service URL 
export RETAIL_CATALOGUE=$(minikube service --url retail-store-service) 

# Check the commands endpoint 
curl $RETAIL_CATALOGUE/commands
  1. Install the Infinispan Operator
curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.19.1/install.sh | bash -s v0.19.1
kubectl create -f https://operatorhub.io/install/infinispan.yaml
kubectl get csv -n operators

You should see

NAME                         DISPLAY               VERSION   REPLACES                     PHASE
infinispan-operator.v2.2.1   Infinispan Operator   2.2.1     infinispan-operator.v2.2.0   Succeeded
  1. Create Infinispan identities secret
kubectl create secret generic --from-file=identities.yaml connect-secret
  1. Deploy infinispan server
kubectl apply -f infinispan.yaml

You should see something like the following list

 minikube service list    
                                                                                    15:17:03
|-------------|-----------------------|--------------|-----------------------------|
|  NAMESPACE  |         NAME          | TARGET PORT  |             URL             |
|-------------|-----------------------|--------------|-----------------------------|
| default     | infinispan            | No node port |
| default     | infinispan-admin      | No node port |
| default     | infinispan-external   |        11222 | http://192.168.59.101:30000 |
| default     | infinispan-ping       | No node port |
| default     | kubernetes            | No node port |
| default     | postgres              | http/5432    | http://192.168.59.101:31684 |
| default     | retail-store-service  | http/80      | http://192.168.59.101:31056 |
| kube-system | kube-dns              | No node port |
| olm         | operatorhubio-catalog | No node port |
| olm         | packageserver-service | No node port |
|-------------|-----------------------|--------------|-----------------------------|
  1. Build and deploy Inmemory Catalogue
eval $(minikube -p minikube docker-env)
./mvnw clean package -Dquarkus.kubernetes.deploy=true -DskipTests=true 

# Export the service URL 
export INMEMORY_CATALOGUE=$(minikube service --url inmemory-catalogue-service) 

curl $INMEMORY_CATALOGUE

About

SQL Store showcasing capabilities of Infinispan Table and Query caches with persistence

Topics

Resources

Stars

Watchers

Forks