Skip to content

sameershanbhag/Java-Spring-Microservices

Repository files navigation


JAVA-SPRING-MICROSERVICES

◦ Unleashing Power, One Microservice at a Time!

◦ Developed with the software and tools below.

Docker java

GitHub license git-last-commit GitHub commit activity GitHub top language

📖 Table of Contents


📍 Overview

The Java-Spring-Microservices repository offers a comprehensive framework for building scalable applications using a microservices architecture. With components divided into separate functions such as inventory, notification, order, and product handling, the service also features an API gateway for routing and a discovery server for managing inter-service communication. The architecture makes use of Docker for containerization, Maven Wrapper for consistent builds, and Spring Boot for robust testing. Providing resilience, load balancing, and database interactions, it offers a complete infrastructure for Java-based applications.


📦 Features

Feature Description
⚙️ Architecture This is a robust Java-based Microservice architecture with an API Gateway, Discovery Server, and services for inventory, notifications, orders, products.
📄 Documentation The repository lacks README and comments in the code. Proper documentation about setup, usage, and code explanation is lacking.
🔗 Dependencies The project uses Spring Boot, Eureka Server for service discovery, Maven and Docker for build and deployment, and MongoDB as the database.
🧩 Modularity Code is well organized into separate microservices for specific functions, enhancing modularity and ease of modifications.
🧪 Testing Some rudimentary tests are in place, although the overall test strategy doesn't appear to be comprehensive for all services.
⚡️ Performance With implemented load balancing and resilient inter-service communication, the system is designed to perform efficiently.
🔐 Security CSRF protection is disabled, authorization through OAuth2 with JWTs is implemented, and Eureka server endpoints are accessible to all.
🔀 Version Control Clear use of Git as a version control system, but there is a lack of commits on the repository, which shows the infrequency of updates.
🔌 Integrations Interactions between different microservices are managed via the API gateway and the Eureka discovery server. Kafka is used for event handling.
📶 Scalability The system is scalable due to the microservice architecture and use of Spring Boot. However, it would be challenging without a proper continuous integration setup.

📂 Repository Structure

└── Java-Spring-Microservices/
    ├── api-gateway/
    │   ├── Dockerfile
    │   ├── Dockerfile.layered
    │   └── src/
    │       └── main/
    ├── discovery-server/
    │   └── src/
    │       └── main/
    ├── inventory-service/
    │   ├── .mvn/
    │   │   └── wrapper/
    │   ├── mvnw
    │   ├── mvnw.cmd
    │   └── src/
    │       ├── main/
    │       └── test/
    ├── notification-service/
    │   └── src/
    │       └── main/
    ├── order-service/
    │   ├── .mvn/
    │   │   └── wrapper/
    │   ├── mvnw
    │   ├── mvnw.cmd
    │   └── src/
    │       ├── main/
    │       └── test/
    └── product-service/
        ├── .mvn/
        │   └── wrapper/
        ├── mvnw
        ├── mvnw.cmd
        └── src/
            ├── main/
            └── test/

⚙️ Modules

Discoveryserver
File Summary
DiscoveryServerApplication.java The Java Spring microservices code establishes an API gateway, and various services (inventory, notification, order, and product) each with main and test directories. The discovery-server service, enabled with Netflix's Eureka Server, provides registry and failure recovery for distributed microservices. The solution facilitates service discovery allowing microservices to find and communicate with each other with Dockerfile for containerization.
Inventory-service
File Summary
mvnw The provided code represents a script for running a Maven project without requiring the user to install and set up Maven manually. The script checks system specifics, sets environment variables, searches the project base directory, and downloads the Maven wrapper jar file if it's not found. It also checks for JAVA_HOME and JAVACMD. The script verifies the SHA-256 sum of the Maven wrapper jar file, executes Maven commands, and handles project configurations.
mvnw.cmd The presented code is an Apache Maven Wrapper startup batch script for a Java application. The script initiates the build process, validates the Java installation by checking the JAVA_HOME environment variable, and establishes directory paths. It also handles the Maven wrapper's download if it's missing, and validates its SHA-256 sum. Besides, it supports environment variables to enable echoing, pausing and customization of Maven parameters. If any issues arise during execution, it returns an appropriate error code.
Inventoryservice
File Summary
InventoryServiceApplicationTests.java The provided code and directory layout illustrate a microservices architecture built with Java Spring, which encompasses an API gateway, and discovery, inventory, notification, order, and product services. Each service, excluding the gateway and discovery server, includes Maven wrapper files. The Java code represents a basic Spring Boot test for the Inventory Service, ensuring its application context loads correctly.
InventoryServiceApplication.java The directory structure represents the microservices architecture for an application in Java Spring, including services for API Gateway, Discovery, Inventory, Notifications, Orders, and Products. The Java code snippet is for an inventory service application, which uses Spring Boot with integrated discovery client for service registry, though it has a comment block for loading data into an inventory repository that currently is not in operations.
Resources
File Summary
data.sql The code snippet belongs to a microservices-based architecture developed using Java and Spring. Different services like API Gateway, Discovery Server, Inventory, Notification, Order, and Product service have their independent components. Each service has its source code and testing files. The SQL script in the Inventory Service creates a inventory_service database if it doesn't exist, enabling storage management for inventory data.
data.sql The provided code corresponds to a directory tree for a Java microservices architecture built with Spring, composed of separate services for API gateway, discovery server, and distinct inventory, order, notifications, and product sub-systems. Each service includes its own source and testing area. The specific script shown creates a database for the order service if it doesn't already exist.
Controller
File Summary
InventoryController.java This is a microservices architecture in Java using the Spring framework, comprising of an API gateway, a discovery server, and four distinct microservices: inventory, notification, order, and product services. Each microservice has its own source code and test suite. The provided Java code snippet specifically handles HTTP GET requests to the /api/v1/inventory endpoint in the inventory service, checking the stock availability for a list of product SKU codes.
OrderController.java The code is part of a Java Spring application implementing microservices architecture. Specifically, it entails an order service utilizing resilience methods for communication with an inventory service. Via an API, it allows placement of orders. The asynchronous placeOrder method is equipped with circuit breaking, time limiting, and retry mechanisms for handling failures. A fallback method is in place to provide a default response in case of execution problems in downstream services.
ProductController.java The code specifies a products controller in a microservices-based Java Spring application. It includes routes to create a product and get all products via ProductService. The architecture contains different folders for various service modules like order-service, inventory-service with their respective Docker files, sources and tests. An API gateway and a discovery server for managing inter-service communication are also evident in the directory structure.
Repository
File Summary
InventoryRepository.java The directory tree represents a microservices architecture with services for API gateway, discovery, inventory, notifications, orders, and products. Each service has source files and some with Maven wrapper files for managing the project's build. In the InventoryRepository.java file, an interface extends JpaRepository for interacting with the inventory data, and declares a method to find inventory items by their SKU codes.
OrderRepository.java The code and directory structure represent a microservices system developed using Java and Spring. It includes services for order management, inventory, notifications, product details, a discovery server, and an API gateway. The specific Java code is an interface for the Order Repository, extending JpaRepository, allowing CRUD operations on orders, based on Spring Data JPA.
ProductRepository.java This is a Java-Spring framework for microservices architecture, containing services for Product, Order, Inventory, Notification, a Discovery Server and an API Gateway. Each service includes source (src) & test directories. ProductRepository.java interfaces with MongoDB as a repository for product data, extending MongoRepository to use its functionalities. The mvnw and mvnw.cmd files, part of the Maven Wrapper, ensure the Maven build system's correct version usage. Docker files are included for containerization.
Service
File Summary
InventoryService.java The code is a part of a Spring-based microservices architecture consisting of six microservices: Api-gateway, Inventory-service, Order-service, etc. Focusing on InventoryService.java in inventory-service, it contains a method isInStock which queries the inventory repository using SKU codes. It retrieves the stock status and returns a list of InventoryResponse objects, indicating whether each item is in stock.
OrderService.java The given code belongs to a Java Spring microservices architecture and presents an OrderService in the order-service directory. The service manages order placements by checking product availability using the inventory-service. If products are available, it saves the order, sends a notification via Kafka, and returns a success message. If not, an exception is thrown. It also uses tracing for service interactions. The service is transactional, aiding in data consistency.
ProductService.java The presented Java Spring code defines a ProductService within a microservices architecture. It provides functionality for creating a new product; data is received via a ProductRequest object, persisted in a repository, and logged. It also retrieves all products from the repository, maps each product to a ProductResponse object, and returns the responses in a list. Dockerfiles and Maven wrapper files indicate built-in support for containerization and standardized builds.
Model
File Summary
Inventory.java This code is part of a Java-Spring-Microservices project encompassing different modules e.g. API gateway, discovery server, and various services including inventory, notification, order, and product. The provided Java class (Inventory) represents the inventory model in the inventory service. It uses Jakarta Persistence for ORM mapping, and Lombok library for simplifying data encapsulation. It has attributes like id, skuCode, and quantity, with necessary getters, setters, and constructors.
Order.java The code is part of a Java Spring microservice system involving services for orders, notifications, inventory, products, and an API gateway with a discovery server. In the Order.java class, ORM is used with Jakarata persistence. It represents an order table with fields for ID, order number, and a list of order line items. It utilizes Lombok annotations for boilerplate code reduction. The service can presumably be built and run using Maven, as suggested by the.mvn directories.
OrderLineItems.java The directory structure represents a Java-Spring-Microservices project. Individual services like API gateway, discovery server, and domain-focused microservices (inventory, notification, order, and product services) are present. Maven Wrapper is used for ensuring consistent Maven builds. In the Order Service, a POJO class OrderLineItems represents an entity in a database with properties like ID, SKU code, price, and quantity to model line items in an order.
Product.java The given code is part of a Java Spring microservices architecture, including services for products, orders, inventory, notifications, a discovery server, and an API gateway. The specific code is a Product model class in the product service, providing a structure for product data with fields for id, name, description, and price. It is annotated for MongoDB mapping and set up for Lombok's automatic builder, data, and constructors support.
Dto
File Summary
InventoryResponse.java The code describes an Inventory Response model in a Java Spring Microservices architecture. It's part of the inventory service, representing output data with inventory status. Annotations imply usage of the Lombok library for automatic boilerplate code generation such as getters, setters, constructors, and a builder pattern. It has two fields-skuCode (representing inventory identifier) and isInStock (representing availability status).
OrderLineItemsDto.java The given project is a modular Java Spring microservices architecture. It includes modules for an API gateway, a discovery server, and service modules for inventory, notifications, orders, and products. The presented code defines an OrderLineItemsDto class, which is a data transfer object used in the order service to hold data related to ordered items, including an id, SKU code, quantity, and price.
OrderRequest.java The provided code sample belongs to a Java-based microservices architecture using Spring, particularly the order service. The architecture includes an API Gateway, a discovery server, and various services for inventory, notifications, orders, and products. In the OrderRequest.java file, a data transfer object (DTO) is created, employing Lombok annotations for simplifying boilerplate code. The DTO includes a list of OrderLineItemsDto for managing individual order items.
InventoryResponse.java The provided code defines a Java-based microservice architecture using Spring, divided into different components: API gateway, Discovery Server, Inventory, Order, Product, and Notification services. Each, barring the Gateway and Discovery Server, features Maven Wrapper for build automation. In particular, a data transfer object (DTO) InventoryResponse in the order-service is detailed, which carries information on SKU code and stock availability.
ProductRequest.java The provided code and directory structure represent a Java Spring microservices architecture. Four specific microservice modules (inventory-service, notification-service, order-service, product-service) use this structure. An api-gateway routes requests, while a discovery-server manages inter-service communication. The ProductRequest Java class in the product-service module captures details(name, description, price) about a product request, using auto-generated getters, setters, and constructors from the Lombok library.
ProductResponse.java The code represents a Java-Spring-Microservices project structure consisting of an API gateway, discovery-server, and multiple microservices: inventory, notification, order, product. Each microservice has a Maven wrapper for build automation. The snippet is a Data Transfer Object (DTO) in ProductService, used for encapsulating product data such as id, name, description, and price, and is equipped with getter/setter, builder, and constructors through Lombok annotations.
Order-service
File Summary
mvnw The script is a shell startup script for the Maven Wrapper, a tool to run Maven builds with a specific version of Maven. It checks various environmental variables, including JAVA_HOME and MAVEN_OPTS, and establishes platform compatibility (Cygwin, Darwin, or Mingw). It determines the Maven project base directory, downloads and validates the Maven Wrapper jar file if it doesn't exist, sets MAVEN_OPTS, and finally initializes and starts the Maven Wrapper with the pre-established configuration variables and any command-line arguments.
mvnw.cmd The given code is a batch script for Maven Wrapper, used for initiating Maven builds in the Java project order-service. It verifies the JAVA_HOME path, finds the Maven base directory, and checks whether Maven Wrappers are available. If not available, it downloads the Maven wrapper from a specified URL. The script also reads any additional JVM configurations, prepares the Maven command line arguments, and executes the Maven operation. It handles errors and sets the suitable exit status.
Orderservice
File Summary
OrderServiceApplicationTests.java The provided directory structure and code represent a Spring-based microservices system composed of an API gateway, discovery server, and four service modules: inventory, notification, order, and product. Each service has a source (src) and test script directory. The order service includes a basic Spring Boot test class, OrderServiceApplicationTests, that checks if the application context successfully loads.
OrderServiceApplication.java The provided Java Spring Microservices code base includes services for managing orders, inventory, notifications, and products. Each service incorporates source code and tests. The OrderServiceApplication initiates the Order Service microservice and enables it as a discovery client to communicate with the Discovery Server. Dockerfile in the API gateway aids containerization. The Maven Wrapper present suggests independence from local Maven installation.
Event
File Summary
OrderPlacedEvent.java The code defines a Java object in a Spring-based microservices architecture for order management operations. It represents an OrderPlacedEvent with an order number field. This event is likely used within the system to signal when an order is placed. The project also includes an API gateway, a discovery server, and additional services for inventory, notifications, and products, each with its source code and Docker implementation files.
Config
File Summary
WebClientConfig.java The provided code is part of a Java Spring Microservices project. Specifically, it is a configuration class within the order-service module named WebClientConfig. This class contains a single method that creates a load-balanced WebClient.Builder bean. This bean can be used to make HTTP requests to other services with load balancing capabilities, optimizing resource usage within distributed microservice environments.
SecurityConfig.java The code provided is a configuration class utilizing Spring Security to deal with security concerns in a microservices-based Java Enterprise application. It disables Cross-Site Request Forgery (CSRF), allows all access to Eureka server endpoints, and requires authentication for all other requests, particularly those to /api/**. It also establishes the requirement for OAuth2 authentication, using JSON Web Tokens (JWTs). The service includes an API gateway, discovery server, and order, inventory, notification, and product services.
Product-service
File Summary
mvnw The directory tree represents a Java Spring Microservices project. It contains an API gateway for routing, a discovery server for locating services, and separate microservices for inventory management, notifications, order processing, and product management. Each microservice, including the API gateway, has its own source code. The project is Docker compatible, with Dockerfiles provided. The use of the Maven Wrapper (mvnw) enables building the project without installing Maven.
mvnw.cmd This is a directory structure for a Java Spring microservices based application. It contains an API gateway, discovery server and four microservices namely; Inventory, Notification, Order, and Product. Each service along with the gateway has its own Dockerfiles for containerization. Maven wrapper files (.mvnw, mvnw.cmd) in the services facilitate building the project, ensuring the usage of correct Maven version.
Productservice
File Summary
ProductServiceApplicationTests.java This code represents a test class for a product service application within a larger, microservices-oriented Java Spring application. The test class is configured to use a MockMvc instance, an ObjectMapper, and a MongoDB test container. There are test cases for product creation and retrieving all products, verifying API response statuses. The code uses Spring's @SpringBootTest, @Testcontainers, and @AutoConfigureMockMvc annotations, and leverages Testcontainers for MongoDB integration testing.
ProductServiceApplication.java This Java project employs Spring Boot and Microservices architecture, composed of an API Gateway, Discovery Server, and four service modules: Inventory, Notification, Order, and Product. Each module has its native Maven wrapper for dependency management. The Product Service code demonstrates a Spring Boot application enabling a Discovery Client, allowing this service to register itself with the Discovery Server for service discovery.
Notificationservice
File Summary
OrderPlacedEvent.java The given code represents a microservices-based Java Spring application architecture. It consists of different services such as api-gateway, discovery-server, inventory, notification, order, and product services, each with its own source code and testing. Specifically, the OrderPlacedEvent.java under the notification service is a simple data container for orderNumber. It employs Lombok library to automatically generate getter, setter, no-argument, and all-argument constructors.
NotificationServiceApplication.java This Java Spring microservice project incorporates an API Gateway, a discovery server, and separate services for inventory, notifications, orders, and products. The presented code is for the notification service. It runs a Spring Boot application and listens to a Kafka topic to handle notifications. When an order event is received, it prints and logs a message indicating a notification has been sent for that order number. Future scope includes sending email notifications.
Api-gateway
File Summary
Dockerfile.layered The code defines a multi-staged Dockerfile for an API Gateway in a Spring-based microservices architecture. It utilizes Java 17 JRE from eclipse-temurin and works in layered mode to extract components of a Spring Boot jar file into separate image layers. It exposes the application on port 8080, and launches it via org.springframework.boot.loader.JarLauncher. The architecture includes separate services for inventory, notifications, orders, and products, alongside a discovery server.
Dockerfile The code describes a hierarchy for a Java Spring Microservices project, comprising several services including API Gateway, Discovery Server, and business services for inventory, notifications, orders, and products. Each service has its source code, some with Maven wrappers. The api-gateway service is Dockerized using a Dockerfile to create an image with OpenJDK 17, copying a JAR file into the image and setting it as the entrypoint.
Apigateway
File Summary
APIGatewayApplication.java The provided tree structure and code represents a Java Spring microservices-based application. It includes an API Gateway for routing requests, a discovery server for service discovery, and separate microservices for managing inventory, orders, products, and notifications. Every microservice, apart from the gateway and discovery server, has a Maven wrapper for build automation. The gateway's Java code launches the application and enables service discovery.

🔧 Installation

  1. Clone the Java-Spring-Microservices repository:
git clone https://github.com/sameershanbhag/Java-Spring-Microservices
  1. Change to the project directory:
cd Java-Spring-Microservices
  1. Install the dependencies:
mvn clean install

🤖 Running Java-Spring-Microservices

java -jar target/myapp.jar

🧪 Tests

mvn test

🤝 Contributing

Contributions are welcome! Here are several ways you can contribute:

Contributing Guidelines

Click to expand
  1. Fork the Repository: Start by forking the project repository to your GitHub account.
  2. Clone Locally: Clone the forked repository to your local machine using a Git client.
    git clone <your-forked-repo-url>
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear and concise message describing your updates.
    git commit -m 'Implemented new feature x.'
  6. Push to GitHub: Push the changes to your forked repository.
    git push origin new-feature-x
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.

Once your PR is reviewed and approved, it will be merged into the main branch.


📄 License

This project is protected under the MIT License. For more details, refer to the LICENSE file.


👏 Acknowledgments

Return


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published