GithubHelp home page GithubHelp logo

ansaritariq / microservices_architecture Goto Github PK

View Code? Open in Web Editor NEW
13.0 5.0 12.0 42 KB

Microservice with spring boot, eureka, zuul and oauth

Java 100.00%
spring-boot spring-cloud netflix-eureka netflix-zuul oauth2 microservices microservice

microservices_architecture's Introduction

Microservice with spring boot, eureka, zuul and oauth

This project demonstrate microservice architecture using spring boot, srping cloud, netfilx eureka, netflix zuul, and oauth.

microservices_architecture

Contains four component all of them are independently deployable applications.

service-registrar

This service maintain the registry of all the microservices that has been deployed. I have used netflix eureka in this project. To register service to service-registrar we need to specify property like below.

eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

routing-server or api gateway

The client can make request to each of the microservices directily, to do that client needs to know all the endpoint addresses but there are challenges with this option. Things would have been easy for a client if we had a single entry point which routes the request to the appropriate backend service. To provide single entry point I have used netflix zuul, we need to configure zuul to route the request by specifying routes using properties under zuul.routes.NAME where NAME is the application name as per spring.application.name property. Below is the routing configuration for order-service.

zuul.routes.order-service.path=/order-api/**

authentication-service

To access any resource authentication is required. Instead of using the resource owner's credentials to access protected resources, the client obtains an access token.

Generate access token

To generate access token basic authorization header with client id and secret encoded in Base64 should be passed as authorization header.

Name Value
Client Id trusted-app
Secret password

request

POST /auth-api/oauth/token HTTP/1.1
Accept: application/json;charset=UTF-8
Authorization: Basic dHJ1c3RlZC1hcHA6cGFzc3dvcmQ=
Host: localhost:8765
Content-Type: application/x-www-form-urlencoded

grant_type=password&username=demo&password=password

response

{
    "access_token": "02db66a1-6bd0-4240-bed4-556ec3fdfc6c",
    "token_type": "bearer",
    "refresh_token": "06b8a0c8-5ef5-4b77-87ef-c7256bab7c17",
    "expires_in": 44512,
    "scope": "read write trust",
    "name": "Demo"
}
  • Resources can be access using access token either by passing access_token in url <resource_url>?access_token=<access_token> or by passing as authrization header Authorization: Bearer <access_token>. This document will use Authorization header to access resources.

order-service

To access api of order-service the user needs to be authenticated via authentication-service.

request

GET /orders HTTP/1.1
Accept: application/json;charset=UTF-8
Authorization: Bearer 02db66a1-6bd0-4240-bed4-556ec3fdfc6c
Host: localhost:8765
Content-Type: application/json

microservices_architecture's People

Contributors

ansaritariq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

microservices_architecture's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.