Spring Boot microservice for Products Search
This project implements search functionality for the products. It consumes data about products from Kafka topic and stores it into Elasticsearch. Afterwards it can be searched using REST API.
Product operations
Service has Kafka consumer for Create, Update and Delete operations with products:
- Create - service consumes product create message from products topic of Kafka and stores products into Elasticsearch. Product can be searched via Nordmart Web after that.
- Update - service consumes product update message from products topic of Kafka and updates product in Elasticsearch. Updated product can be searched via Nordmart Web after that.
- Delete - service consumes delete command from products topic of Kafka and deletes product from Elasticsearch. Product no longer available for search via Nordmart Web after that.
Search operations
User can search for product using Nordmart Web. In this case GET request is performed to "/api/v1/product-search" URL with criteria parameter(string with product name or description that user searches for). Service passes criteria in query to Elasticsearch and returns found products as response. In this way all the products in the system can be searched.
It requires following things to be installed:
- Java: ^8.0
- Maven
To run the application locally use the command given below:
mvn spring-boot:run
To deploy app inside a docker container
-
Create a network if it doesn't already exist by executing
docker network create --driver bridge nordmart-apps
-
Build jar file of the app by executing command given below:
mvn clean package
-
Next build the image using
docker build -t products-search .
-
Finally run the docker compose
docker-compose up
Helm operator needs to to be running inside the cluster. Helm operator is deployed by Stakater Global Stack, deployment guidelines are provided in this link
To create helm release of this application using the command given below:
kubectl apply -f helm-release.yaml -n
Products search service consumes data from topic with name 'productsTopic', it can be configured using stakater-nordmart-search.kafka.product.topic.name property. Application consumes 3 types of messages in JSON format called commands:
- productCreate - used to create product
- productUpdate - used to update particular product
- productDelete - used to delete particular product
GET /api/v1/product-search
- Perform products search with provided criteria.
- Create a Kubernetes Cluster by following the steps here.
Can be found in application.yml:
Kafka connection configuration
- stakater-nordmart-search.kafka.product.topic.name - name of the topic from which all the product commands are consumed
- stakater-nordmart-search.kafka.product.topic.create.on-startup - boolean property which defines if topic should be created on startup
- stakater-nordmart-search.kafka.product.topic.create.number-of-partitions - number of partitions on which this topic is divided
- stakater-nordmart-search.kafka.product.topic.create.replication-factor - topic replication factor
- stakater-nordmart-search.kafka.bootstrap-servers - Kafka bootstrap servers
CORS configuration
- stakater-nordmart-search.cors.allowed.hosts - CORS allowed hosts
Elasticsearch connection configuration
- stakater-nordmart-search.elasticsearch.host - Elasticsearch host
- stakater-nordmart-search.elasticsearch.port - port of Elasticsearch
- stakater-nordmart-search.elasticsearch.username - username for Elasticsearch
- stakater-nordmart-search.elasticsearch.password - password for Elasticsearch
Server configuration
- spring.application.name - application name
- server.servlet.contextPath - servlet context path
- server.error.include-stacktrace - stacktraces should no be included in case if not handled error happens
- server.host - server hostname
- server.port - server hostname
Application management configuration
- management.endpoint.metrics.enabled - if micrometer metrics is enabled
- management.endpoint.prometheus.enabled - if prometheus is enabled
- management.endpoints.web.exposure.include - which management endpoints are exposed
- management.metrics.export.prometheus.enabled - whether exporting of metrics to Prometheus is enabled.
- Debug failed test due to docker environment issue in tekton