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.
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
- Clone the repository:
https://github.com/knoldus/java-competency-demo
-
Open the project in your favorite IDE or code editor.
-
Configure the Azure/GCP credentials and other necessary configurations in the
application.yml
,application-cosmos.yml
,application-firestore.yml
file. -
Build the application using Maven:
mvn clean package
- Run the application
mvn spring-boot:run -Dspring.profile.active=cosmos
- 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>
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 =
- Push data to cloud Pub-sub
- Endpoint:
/v1/data
- HTTP method: POST
- Endpoint:
- Get brands data from reactive mogo repository
- Endpoint:
/v1/data/brands
- HTTP method: GET
- Endpoint:
- Get data from reactive mongo repository
- Endpoint:
/v1/data/cars/{brand}
- HTTP method: GET
- Endpoint:
- Get all unique brands from reactive firestore repository
- Endpoint:
/v1/data/cars/brands-sse
- HTTP method: GET
- Endpoint:
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.
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