Skip to content

shrihari7396/GRPCLearnedSotckProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Stock Trading gRPC Project

Welcome to the Stock Trading gRPC project! This repository contains a simple, high-performance client-server application demonstrating how to build and communicate using gRPC (gRPC Remote Procedure Calls) and Protocol Buffers (Protobuf) within the Spring Boot ecosystem.

📌 Project Overview

This project consists of two main Spring Boot modules:

  1. StockTradingServer: A gRPC server that handles requests for stock prices. It uses Spring Data JPA to fetch stock details from a MySQL database and returns them to the client.
  2. Stock-trading-client: A gRPC client that connects to the server. It uses a blocking stub to send requests for specific stock symbols and receives the corresponding stock prices.

Key Features

  • gRPC Communication: Utilizes gRPC for fast and efficient binary communication between the client and server.
  • Protocol Buffers: Defines the service contract (StockTradingService) and message payloads (StockRequest, StockResponse) in an language-agnostic .proto file.
  • Spring Boot Integration: Leverages spring-grpc-spring-boot-starter on the server and grpc-client-spring-boot-starter on the client for seamless autoconfiguration.
  • Database Integration: The server uses Spring Data JPA and MySQL to persist and retrieve mocked stock data (Stock entity).

🛠️ Technology Stack

  • Java: Primary programming language (Java 17).
  • Spring Boot: Framework for both client and server applications (Version 3.5.3).
  • gRPC & Protobuf: For defining services and messaging (grpc-netty-shaded, protobuf-java).
  • Database: MySQL Server (mysql-connector-j) & Spring Data JPA.
  • Build Tool: Maven (with os-maven-plugin and protobuf-maven-plugin for Protobuf compilation).
  • Lombok: To reduce boilerplate code in Data models and Entities.

📂 Project Structure

  • StockTradingServer/src/main/proto/stock_trading.proto: Contains the service definition (getStockPrice) and message structures.
  • StockTradingServer/src/main/java/edu/pict/StockTradingServer/service/StockTradingServiceImplementation.java: Implements the gRPC service base class generated by Protobuf and handles the business logic (fetching from DB).
  • Stock-trading-client/src/main/java/edu/pict/Stock_trading_client/service/StockClientService.java: Sets up the gRPC client stub using @GrpcClient and makes blocking calls to the server.

🚀 How to Run

1. Prerequisites

  • Java 17 and Maven installed.
  • MySQL server running locally.

2. Database Setup

Ensure you have a MySQL database created (check the application.properties or .yml in StockTradingServer for the exact database name, username, and password).

3. Build the Project

Before running the applications, you must compile the Protobuf files to generate the necessary Java classes and gRPC stubs. Navigate to both module directories (StockTradingServer and Stock-trading-client) and run:

mvn clean install

(This triggers the protobuf-maven-plugin to generate the sources).

4. Start the Server

Navigate to the StockTradingServer directory and run the Spring Boot application:

mvn spring-boot:run

The gRPC server will start and listen for incoming connections on the configured port (default is usually 9090 for gRPC).

5. Start the Client

Navigate to the Stock-trading-client directory and run the Spring Boot application:

mvn spring-boot:run

The client will start up, establish a channel to the server, and you can test the gRPC communication (e.g., via a REST controller or CommandLineRunner setup in the client).


Built to explore the power and efficiency of gRPC in modern Java microservices!

About

A Spring Boot client-server application demonstrating high-performance communication using gRPC and Protocol Buffers for stock trading data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages