Skip to content

Latest commit

 

History

History
77 lines (77 loc) · 4 KB

File metadata and controls

77 lines (77 loc) · 4 KB

Microservices-JWT-Zuul-Kafka-docker

This repository would help beginners understand how to start with simple microservices having an api gateway and registering all your microservices in eureka-server and dockerize of all it.

In this project we have
Auth Service which does users signup and signin
Users Service which provides apis to fetch all user details and details of any specific user who is signed up using Auth service.
Products Service which has got list of products users can order.(These products are hardcoded for now).
Orders Service which helps users to order for the products.
Invoices Service which gives out users invoice for the ordered prodcuts.
Zuul Service which serves as api gateway for all the above mentioned services.
EurekaServer which registers all our services.

Role Of Kafka
To send users information who registered via Auth Service to Users Service.
To send orders information placed via Orders Service to Invoices Service.

Databases
We use postgres:9.5 image.
Auth Service - authservicedb
Orders Service - orders
Invoices Service - invoices

How To Run?
Every microservice has got docker-maven-plugin in their pom. Reach the folder of each microservice and run
mvn clean install docker:build
Above command creates a dockerfile in the respecitve target folder of that service and the relative path of dockerfile is used in docker-compose.
Now cd into the docker folder in the repository here and run below commands.
sudo docker-compose build
sudo docker-compose -f docker-compose.yml up
Now you should be able to see all the services up and running

How To Use?
We need to get the ip of the docker container which is running Zuul api gateway
List all docker containers.
sudo docker container ps
Check for the id of the container which is runnig zuul image and inspect it to get the ip.
sudo docker inspect
Let the ip of the api gateway be ip_gateway.
Register an user - (POST) http://ip_gateway:8082/api/auth/users/signup
Payload
{ "name":"John", "username":"joe", "email":"[email protected]", "password":"qwedsa" }
Response
{ "usernameOrEmail":"[email protected]", "password":"qwedsa" }
Login of an user - (POST) http://ip_gateway:8082/api/auth/signin
Payload
{ "usernameOrEmail":"[email protected]", "password":"qwedsa" }
Response
{ "accessToken": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNTQwMTI5NjI4LCJleHAiOjE1NDA3MzQ0Mjh9.fvwXFjTV7YlbkLItFg- kAVfXpW9ciwfM3Lgy2UIKdJNWFcuRFQPW6NKQz_xJ1YaLgpAdq-VRojMuQ6SIXiVHkA", "tokenType": "Bearer" }
To Access Any Apis Of Other Services We Should Be Using Above Obtained AccessToken
For example Authorization header would be
Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNTQwMTI5NjI4LCJleHAiOjE1NDA3MzQ0Mjh9.fvwXFjTV7YlbkLItFg- kAVfXpW9ciwfM3Lgy2UIKdJNWFcuRFQPW6NKQz_xJ1YaLgpAdq-VRojMuQ6SIXiVHkA
Get all Products - (GET) http://ip_gateway:8082/products
Get all Users - (GET) http://ip_gateway:8082/users
Get user details of user with userId 1 - (GET) http://ip_gateway:8082/users?userId=1
Create order for an user with userId 1 - (POST)http://ip_gateway:8082/order?userId=1&productname=product3&price=1000
You can use any of the products obtained from above get all products api to place an order.
Get all orders of an user with userId 1 - (GET) http://ip_gateway:8082/orders?userId=1
Get all invoices of an user with userId 1 - (GET) http://ip_gateway:8082/invoices?userId=1