Skip to content

Latest commit

 

History

History
110 lines (80 loc) · 4.02 KB

README.md

File metadata and controls

110 lines (80 loc) · 4.02 KB

Spring Boot Reactive Application for Azure/GCP Cloud Services

This is a sample Spring Boot reactive application that demonstrates how to interact with the cloud services of Azure/GCP to push data into a Pub-Sub system and fetch data from the cloud-managed reactive MongoDB repositories. This application is built using Spring WebFlux, Spring Data Reactive MongoDB, and the respective cloud SDKs for Azure/GCP.

Table of Contents

Prerequisites

Before running the application, make sure you have the following installed:

  • Java Development Kit (JDK) 11 or higher
  • Maven (for building and managing dependencies)
  • Azure/GCP Cloud account with appropriate credentials and access to Pub-Sub and Reactive MongoDB services.
  • Google SDK setup on local terminal

Getting Started

  1. Clone the repository:
https://github.com/knoldus/java-competency-demo
  1. Open the project in your favorite IDE or code editor.

  2. Configure the Azure/GCP credentials and other necessary configurations in the application.yml, application-cosmos.yml, application-firestore.yml file.

  3. Build the application using Maven:

mvn clean package
  1. Run the application
mvn spring-boot:run -Dspring.profile.active=cosmos

Application Structure

High-level diagram

HLD

Sequence diagram

sequencediagram

Class diagram

classDiagram

Configuration

Azure config

  • cosmosdb.key = <COSMOS_KEY>
  • cosmosdb.uri = <COSMOS_URI>
  • kafka.bootstrap-servers= ${KAFKA_SERVER}
  • kafka.properties.security.protocol = <KAFKA_SECURITY_PROTOCOL>
  • kafka.properties.sasl.mechanism = <SASL_MECHANISM>
  • kafka.properties.sasl.jaas.config = <JASS_CONFIG>
  • kafka.producer.key-serializer = <KEY_SERIALIZER>
  • kafka.producer.value-serializer = <VALUE_SERIALIZER>

GCP config

Obtain the JSON Key: If you don't have the JSON key for your Google Cloud service account, you can generate one from the Google Cloud Console. Navigate to the "IAM & Admin" section and create a new service account. Then, generate and download the JSON key for that service account.

  • google.application.credentials = <GOOGLE_APPLICATION_CREDENTIALS>
  • google.application.pubSub.topic =
  • spring.cloud.gcp.project-id =

REST endpoints

  • Push data to cloud Pub-sub
    • Endpoint: /v1/data
    • HTTP method: POST
  • Get brands data from reactive mogo repository
    • Endpoint: /v1/data/brands
    • HTTP method: GET
  • Get data from reactive mongo repository
    • Endpoint: /v1/data/cars/{brand}
    • HTTP method: GET
  • Get all unique brands from reactive firestore repository
    • Endpoint: /v1/data/cars/brands-sse
    • HTTP method: GET

Dependencies

The main dependencies used in this application are:

  • Spring Boot Starter WebFlux: Provides the necessary components for building reactive web applications.

  • Spring Boot Starter Data MongoDB Reactive: Allows the application to interact with the reactive MongoDB repositories.

  • Azure SDK or GCP SDK: The SDK for the respective cloud provider is used to interact with the Pub-Sub service.

For a complete list of dependencies, please refer to the pom.xml file in the project.

Sonar Configuration

We have integrated sonar in our project for inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security.

Execute the following Maven command to run Sonar analysis:

mvn clean verify sonar:sonar

Sonar report

sonarReport.png