Skip to content

UsmanAttiq7/GoLang-Microservice-Task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GO GRPC Microservices

This repository contains 3 GRPC microservices:

  • User Service: This service is responsible for user management.
  • Booking Service: This service is responsible for booking management.
  • Ride Service: This service is responsible for ride management.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • POSTGRES - The root of the repo contains a docker folder with a docker-compose file that will spin up a PG database with initial seed data for the services.
  • GO - The services are written in Go. You will need to have Go installed on your machine.

Navigate to a service folder ( user-service / booking-service / ride-service ) and run the following commands to start the service:

  • go mod tidy to install all the dependencies for each service which are defined in the go.mod under each respective service folder.

  • go run ./cmd/main.go to start the service.

Each service has .env pre-configured to run with the docker-compose PG database on port 5432.

User Service

After starting the user service, you can access the user service on http://localhost:50051. Use the following grpcurl commands to interact with the user service:

  • Get a User by user_id
grpcurl -plaintext -d '{"user_id": 1}' localhost:50051 user.v1.UserService/GetUser
  • Create a User
grpcurl -plaintext -d '{"name": "Bilal"}' localhost:50051 user.v1.UserService/CreateUser
  • Delete a User
grpcurl -plaintext -d '{"user_id": 4}' localhost:50051 user.v1.UserService/DeleteUser

Booking Service

After starting the booking service, you can access the booking service on http://localhost:50052. Use the following grpcurl commands to interact with the booking service:

  • Get a Booking by booking_id
grpcurl -plaintext -d '{
  "booking_id": 1  
}' localhost:50052 booking.v1.BookingService/GetBooking
  • Create a Booking
grpcurl -plaintext -d '{
  "user_id": 1,
  "ride": {
    "source": "Downtown",
    "destination": "Airport",
    "distance": 15,
    "cost": 250
  }
}' localhost:50052 booking.v1.BookingService/CreateBooking

Ride Service

After starting the ride service, you can access the ride service on http://localhost:50053. Use the following grpcurl commands to interact with the ride service:

  • Update a Ride by ride_id
grpcurl -plaintext -d '{
  "ride_id": 1,
  "ride": {
    "source": "Downtown",
    "destination": "Mall",
    "distance": 10,
    "cost": 200
  }
}' localhost:50053 ride.v1.RideService/UpdateRide

Metrics

  • User-Service : http://localhost:9005/metrics
  • Booking-Service : http://localhost:9006/metrics
  • Ride-Service : http://localhost:9007/metrics

Unit Tests

Units tests for the GRPC services can be found under <service-name>/internal/service/<service-name>_test.go

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages